pgmem
Reference

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

FieldTypeDefaultWhen to touch
poolPoolConfigPoolConfig()Concurrency / connection sizing.
fulltextFullTextConfigFullTextConfig()Choosing a BM25 backend.
ingestionIngestionConfigIngestionConfig()Tuning dedup, retries, size limits.
searchSearchConfig | NoneNone (auto-pick)Forcing a specific retrieval recipe.
compilerCompilerConfigCompilerConfig()Retrieval depths, tokenizer, live-context provider.
communityCommunityConfigCommunityConfig()Community rebuild limits.

PoolConfig

FieldDefaultNotes
min_size1
max_size10Needs ≥ 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

FieldDefaultNotes
backendFullTextBackend.autoauto 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.

FieldDefaultNotes
strategy_depthssee belowPer-strategy retrieval depths. Every built-in strategy must be present.
tokenizerTokenizerConfig()Token accounting for budgets.
injected_context_providerNoneA (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):

Strategyepisodicnarrativesemantic
conversation535
task803
recall388

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:

FieldDefaultNotes
node_dedup_candidate_limit15Cosine candidates considered when deduping an entity.
node_dedup_min_score0.6Similarity floor for an entity dedup candidate.
edge_invalidation_candidate_limit10Candidates checked for contradiction.
edge_dedup_cosine_thresholdNoneOptional fast-path edge dedup by cosine.
previous_episode_limit10Prior episodes fed as extraction context.
retries3Embedder/LLM retry attempts.
bulk_concurrency20Parallel per-episode resolvers in bulk ingest.
update_communitiesFalseIncremental community update after each episode.
expected_embed_dim1536Must 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

FieldDefaultNotes
max_concurrent_builds10Cap on simultaneous per-community LLM reductions — set to your provider's limit.
label_propagation_max_iterations100Clustering loop cap.
max_summary_chars1000Community summary cap.

Policies (injected, not in config)

ObjectPassed asConcept
ClaimPolicyPgMem(claim_policy=...)Trust & memory formation — governs claim formation, evidence, conflicts, and live-state routing.

On this page