pgvector Storage
For common Agent integration, extraction modes, and tool configuration, see Usage and Configuration.
Use case: Production, vector similarity search with PostgreSQL + pgvector
Set PGVECTOR_DSN through environment or secret management. A production DSN
should validate the server certificate and use a host name covered by it:
Configuration options:
WithPGVectorClientDSN(dsn): Recommended connection form; has the highest priorityWithHost/WithPort/WithUser/WithPassword/WithDatabase: Alternative field-based connection parametersWithSSLMode(mode): SSL mode (default "disable")WithPostgresInstance(name): Use pre-registered PostgreSQL instanceWithEmbedder(embedder): Text embedder for vector generation (required)WithSoftDelete(enabled): Enable soft delete (default false)WithTableName(name): Custom table name (default "memories")WithSchema(schema): Specify database schema (default is public)WithIndexDimension(dim): Vector dimension (default 1536)WithMaxResults(limit): Max search results (default 10)WithMemoryLimit(limit): Memory limit per userWithCustomTool(toolName, creator): Register custom toolWithToolEnabled(toolName, enabled): Enable/disable toolWithExtraOptions(...options): Extra options passed to PostgreSQL clientWithSkipDBInit(skip): Skip table initialization (for users without DDL permissions)WithHNSWIndexParams(params): HNSW index parameters for vector search
Note: A DSN takes priority over the field-based connection parameters. Both
direct forms take priority over WithPostgresInstance. The default SSL mode is
disable; use it only for trusted local development, not production. The
pgvector extension must be installed in PostgreSQL.
Default initialized schema:
The service enables the vector extension and initializes public.memories
with vector, episodic, and full-text fields. WithTableName, WithSchema, and
WithIndexDimension replace memories, public, and 1536. It also creates
indexes for app/user, update time, deletion time, event time, kind,
participants (GIN), embedding (HNSW), and search_vector (GIN), plus a trigger
that maintains search_vector from memory_content.
WithSkipDBInit(true) skips the extension, table, indexes, trigger function,
trigger, and full-text backfill. Provision all of them before starting the
service; use
memory/pgvector/init.go
as the authoritative DDL, including custom HNSW parameters.
Resource cleanup: Call Close() method to release database connection: