@galdor/memory-pgvector
v0.3.1
Published
PostgreSQL + pgvector long-term memory store for galdor-bun: indexed cosine nearest-neighbour search.
Downloads
261
Readme
@galdor/memory-pgvector
A PostgreSQL + pgvector long-term memory
store for galdor, implementing the core memory.Store interface. It drops in
behind a Retriever like the bundled InMemoryStore, but persists vectors in a
Postgres table with an HNSW cosine index, so the nearest-neighbour search runs in
the database and scales to large corpora. This backend is vector-only.
Requires a Postgres server with the vector extension available, and the pg
package installed (a peer dependency) when constructing from a connection string.
Usage
import { openPgVector } from "@galdor/memory-pgvector";
const store = await openPgVector({
connString: "postgres://user:pass@localhost:5432/db",
table: "galdor_chunks", // optional; must match [a-z0-9_]+
dim: 1024,
});
// …or pass your own client: openPgVector({ client: myPgPool, dim: 1024 })
await store.add([{ id: "c1", documentId: "d1", index: 0, text: "…", embedding: vec, metadata: { lang: "es" } }]);
const hits = await store.retrieve({ embedding: queryVec, k: 5, filter: { lang: "es" } });
await store.delete("d1");
await store.close();Behavior
- open runs
CREATE EXTENSION IF NOT EXISTS vector, creates the table (vector(dim)+jsonbmetadata) and adoc_idbtree + HNSW cosine index. - add upserts via
INSERT … ON CONFLICT (id) DO UPDATE(idempotent by id). - retrieve ranks with the
<=>cosine-distance operator (score1 - distance, negatives dropped);filtermaps to JSONB@>containment. - delete removes every row whose
document_idmatches.
