jeevesagent.memory.postgres

Postgres + pgvector Memory backend.

Schema (created by init_schema()):

  • memory_blocks(namespace, name, content, pinned_order, updated_at)

  • episodes(id, namespace, session_id, occurred_at, input, output, embedding vector(N)) with HNSW cosine index on embedding

The vector(N) column dimension is fixed at table-creation time and must match the configured embedder’s dimensions. Switching embedders later requires migrating the table.

Both asyncpg and pgvector are imported lazily inside connect() / init_schema() so the module loads in environments without those extras installed; the import only fires when actually opening a connection.

Attributes

Classes

PostgresMemory

Postgres-backed Memory.

Module Contents

class jeevesagent.memory.postgres.PostgresMemory(pool: Any, *, embedder: jeevesagent.core.protocols.Embedder | None = None, namespace: str = DEFAULT_NAMESPACE, fact_store: Any | None = None)[source]

Postgres-backed Memory.

pool is an asyncpg.Pool (or anything with the same API). Tests can pass a fake pool whose acquire() returns a fake connection.

async aclose() None[source]
async append_block(name: str, content: str) None[source]
classmethod connect(dsn: str, *, embedder: jeevesagent.core.protocols.Embedder | None = None, namespace: str = DEFAULT_NAMESPACE, min_size: int = 1, max_size: int = 10, with_facts: bool = False) PostgresMemory[source]
Async:

Open an asyncpg pool and register the pgvector codec.

When with_facts=True a PostgresFactStore rooted at the same pool is attached as self.facts so the agent loop’s memory.facts integration just works.

async consolidate() None[source]
async init_schema() None[source]

Apply schema_sql() against the connected pool.

When a PostgresFactStore is attached as self.facts, its schema is initialised in the same call.

async recall(query: str, *, kind: str = 'episodic', limit: int = 5, time_range: tuple[datetime.datetime, datetime.datetime] | None = None, user_id: str | None = None) list[jeevesagent.core.types.Episode][source]
async recall_facts(query: str, *, limit: int = 5, valid_at: datetime.datetime | None = None, user_id: str | None = None) list[jeevesagent.core.types.Fact][source]
async remember(episode: jeevesagent.core.types.Episode) str[source]
schema_sql() list[str][source]

Return the DDL needed to bootstrap this backend’s schema.

Exposed so tests can assert on the SQL without running it; also usable from migration scripts that want to apply the schema in their own transaction.

async session_messages(session_id: str, *, user_id: str | None = None, limit: int = 20) list[jeevesagent.core.types.Message][source]
async update_block(name: str, content: str) None[source]
async working() list[jeevesagent.core.types.MemoryBlock][source]
property embedding_dimensions: int
facts: Any | None = None
property namespace: str
jeevesagent.memory.postgres.DEFAULT_NAMESPACE = 'default'