AgentSea.VectorStore.Postgres (agentsea_embeddings v0.1.0)

Copy Markdown

A pgvector-backed AgentSea.VectorStore over Postgrex — the design's first- class production store.

The "store" is a plain map bundling a Postgrex connection with the table name and dimensionality, so it slots into AgentSea.Embeddings exactly like the in-memory store. Vectors are passed as $n::vector text literals (no extra type extension needed); similarity is cosine (<=>); metadata is jsonb.

Setup

{:ok, conn} = Postgrex.start_link(database: "agentsea", hostname: "localhost")
store = AgentSea.VectorStore.Postgres.store(conn, table: "embeddings", dimensions: 1536)
:ok = AgentSea.VectorStore.Postgres.ensure_table(store)

AgentSea.Embeddings.new(store_mod: AgentSea.VectorStore.Postgres, store: store, embedder: ...)

Summary

Functions

Create the pgvector extension and the embeddings table if absent.

Bundle a Postgrex connection into a store. Options: :table, :dimensions (required).

Validate a table identifier (guards against SQL injection via the name).

Encode a vector as a pgvector text literal, e.g. [1.0,2.0,3.0].

Types

store()

@type store() :: %{
  conn: GenServer.server(),
  table: String.t(),
  dimensions: pos_integer()
}

Functions

ensure_table(map)

@spec ensure_table(store()) :: :ok

Create the pgvector extension and the embeddings table if absent.

store(conn, opts)

@spec store(
  GenServer.server(),
  keyword()
) :: store()

Bundle a Postgrex connection into a store. Options: :table, :dimensions (required).

valid_table!(table)

@spec valid_table!(String.t()) :: String.t()

Validate a table identifier (guards against SQL injection via the name).

vector_literal(vector)

@spec vector_literal([number()]) :: String.t()

Encode a vector as a pgvector text literal, e.g. [1.0,2.0,3.0].