AgentSea.Embeddings (agentsea_embeddings v0.1.0)

Copy Markdown

Ties an AgentSea.Embedder to an AgentSea.VectorStore: embed-and-index text documents, then semantic-search by text.

Example

{:ok, store} = AgentSea.VectorStore.Memory.start_link()

handle =
  AgentSea.Embeddings.new(
    store_mod: AgentSea.VectorStore.Memory,
    store: store,
    embedder: AgentSea.Embedder.Hashing
  )

AgentSea.Embeddings.index(handle, [
  %{id: "a", text: "the cat sat on the mat"},
  %{id: "b", text: "quarterly revenue grew 12%"}
])

[%{id: "a"} | _] = AgentSea.Embeddings.search(handle, "where is the cat", 1)

Summary

Functions

Embed each entry's text and upsert it into the store.

Build a handle bundling a store + embedder.

Embed the query text and return the k most similar records.

Types

entry()

@type entry() :: %{:id => term(), :text => String.t(), optional(:metadata) => map()}

t()

@type t() :: %AgentSea.Embeddings{
  embed_opts: keyword(),
  embedder: module(),
  store: GenServer.server(),
  store_mod: module()
}

Functions

index(handle, entries)

@spec index(t(), [entry()]) :: :ok | {:error, term()}

Embed each entry's text and upsert it into the store.

new(opts)

@spec new(keyword()) :: t()

Build a handle bundling a store + embedder.

search(handle, query, k, opts \\ [])

@spec search(t(), String.t(), pos_integer(), keyword()) ::
  [AgentSea.VectorStore.hit()] | {:error, term()}

Embed the query text and return the k most similar records.