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 onembedding
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¶
Postgres-backed |
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.poolis anasyncpg.Pool(or anything with the same API). Tests can pass a fake pool whoseacquire()returns a fake connection.- 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=TrueaPostgresFactStorerooted at the same pool is attached asself.factsso the agent loop’s memory.facts integration just works.
- async init_schema() None[source]¶
Apply
schema_sql()against the connected pool.When a
PostgresFactStoreis attached asself.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 working() list[jeevesagent.core.types.MemoryBlock][source]¶
- jeevesagent.memory.postgres.DEFAULT_NAMESPACE = 'default'¶