Spectre.Classifier (Spectre v0.3.0)

Copy Markdown View Source

Runtime for Spectre's lightweight local vector classifier.

The classifier loads artifacts produced by Spectre.Classifier.Trainer and exposes a route-like result for router plugs. It can run as a GenServer for warm artifacts or load artifacts on demand with classify_once/2.

{:ok, _pid} = Spectre.Classifier.start_link(artifact_dir: "artifacts/spectre")
{:ok, route} = Spectre.Classifier.classify("create a project")

Summary

Functions

Returns a specification to start this module under a supervisor.

Classifies text using a running classifier process when available.

Classifies text by loading artifacts for this call.

Starts a classifier process that keeps the artifact loaded.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

classify(text, opts \\ [])

@spec classify(
  String.t(),
  keyword()
) :: {:ok, Spectre.Route.t()} | {:error, term()}

Classifies text using a running classifier process when available.

{:ok, route} = Spectre.Classifier.classify("show my projects")

classify_once(text, opts)

@spec classify_once(
  String.t(),
  keyword()
) :: {:ok, Spectre.Route.t()} | {:error, term()}

Classifies text by loading artifacts for this call.

{:ok, route} = Spectre.Classifier.classify_once("show my projects", artifact_dir: path)

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Starts a classifier process that keeps the artifact loaded.

Startup options are retained for warm classifications. Options supplied to classify/2 override them for that call.

{:ok, pid} = Spectre.Classifier.start_link(artifact_dir: "artifacts/spectre")