Configuration
Every config object and when to touch it.
All tuning lives in one PgMemConfig you build once and pass as
PgMem(dsn, config=...). Every field has a sensible default, so you only set what
you care about. Flat PgMem(...) keyword overrides still work and win over the
same field in config.
from pgmem import PgMem, PgMemConfig, PoolConfig, IngestionConfig
mem = await PgMem.create(
dsn,
embedder=embedder, llm=llm,
config=PgMemConfig(
pool=PoolConfig(max_size=20),
ingestion=IngestionConfig(edge_dedup_cosine_threshold=0.97),
),
)Providers (embedder / llm / cross_encoder) and the policies
(claim_policy) are not in PgMemConfig — they're
injected directly into PgMem, so config stays pure, loggable data with no
secrets.
PgMemConfig
| Field | Type | Default | When to touch |
|---|---|---|---|
pool | PoolConfig | PoolConfig() | Concurrency / connection sizing. |
fulltext | FullTextConfig | FullTextConfig() | Choosing a BM25 backend. |
ingestion | IngestionConfig | IngestionConfig() | Tuning dedup, retries, size limits. |
search | SearchConfig | None | None (auto-pick) | Forcing a specific retrieval recipe. |
compiler | CompilerConfig | CompilerConfig() | Retrieval depths, tokenizer, live-context provider. |
community | CommunityConfig | CommunityConfig() | Community rebuild limits. |
PoolConfig
| Field | Default | Notes |
|---|---|---|
min_size | 1 | |
max_size | 10 | Needs ≥ 2 for add_episode_bulk, compact_async, and concurrent application/worker activity. Size it for the groups you ingest concurrently. A poll-only projection worker does not hold an idle listener connection. |
FullTextConfig
| Field | Default | Notes |
|---|---|---|
backend | FullTextBackend.auto | auto uses an installed BM25 extension if present, else native Postgres FTS. |
language | "english" | Must match the regconfig baked into the generated tsvector columns (English today). |
CompilerConfig
Controls context compilation.
| Field | Default | Notes |
|---|---|---|
strategy_depths | see below | Per-strategy retrieval depths. Every built-in strategy must be present. |
tokenizer | TokenizerConfig() | Token accounting for budgets. |
injected_context_provider | None | A (session, query) -> list[str] coroutine for always-injected Tier 6 context. Runs on the turn — keep it fast; prefer the per-call injected_context= argument for network calls. |
Default strategy_depths (episodic / narrative / semantic):
| Strategy | episodic | narrative | semantic |
|---|---|---|---|
conversation | 5 | 3 | 5 |
task | 8 | 0 | 3 |
recall | 3 | 8 | 8 |
RetrievalDepths
RetrievalDepths(episodic, narrative, semantic) — non-negative ints; 0 disables a
tier. These are retrieval limits, not token reservations; the compiler still drops
recalled material when the budget requires.
TokenizerConfig
TokenizerConfig(model=None, encoding=None) — set a model (if tiktoken knows it)
or an encoding, not both. Both unset → the default o200k_base encoding.
IngestionConfig
Tuning and safety limits for add_episode. Commonly tuned:
| Field | Default | Notes |
|---|---|---|
node_dedup_candidate_limit | 15 | Cosine candidates considered when deduping an entity. |
node_dedup_min_score | 0.6 | Similarity floor for an entity dedup candidate. |
edge_invalidation_candidate_limit | 10 | Candidates checked for contradiction. |
edge_dedup_cosine_threshold | None | Optional fast-path edge dedup by cosine. |
previous_episode_limit | 10 | Prior episodes fed as extraction context. |
retries | 3 | Embedder/LLM retry attempts. |
bulk_concurrency | 20 | Parallel per-episode resolvers in bulk ingest. |
update_communities | False | Incremental community update after each episode. |
expected_embed_dim | 1536 | Must match the schema's vector(N) width. |
Plus size guards (max_name_chars=512, max_fact_chars=8192,
max_content_chars=65536, max_summary_chars=1000) that protect rows from
oversized input — raise them deliberately.
CommunityConfig
| Field | Default | Notes |
|---|---|---|
max_concurrent_builds | 10 | Cap on simultaneous per-community LLM reductions — set to your provider's limit. |
label_propagation_max_iterations | 100 | Clustering loop cap. |
max_summary_chars | 1000 | Community summary cap. |
Policies (injected, not in config)
| Object | Passed as | Concept |
|---|---|---|
ClaimPolicy | PgMem(claim_policy=...) | Trust & memory formation — governs claim formation, evidence, conflicts, and live-state routing. |
Related
- PgMem — where config is passed
- The context compiler — what
CompilerConfigtunes - Tune retrieval — strategy depths and budgets in practice