pycontextdb 0.4.7__tar.gz → 0.4.9__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. pycontextdb-0.4.9/.github/copilot-instructions.md +49 -0
  2. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/CHANGELOG.md +38 -0
  3. pycontextdb-0.4.9/COMMERCIAL.md +71 -0
  4. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/PKG-INFO +15 -13
  5. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/README.md +8 -9
  6. pycontextdb-0.4.9/ai-tools/.cursorrules +46 -0
  7. pycontextdb-0.4.9/ai-tools/AGENTS.md +11 -0
  8. pycontextdb-0.4.9/ai-tools/CLAUDE.md +67 -0
  9. pycontextdb-0.4.9/ai-tools/README.md +19 -0
  10. pycontextdb-0.4.9/ai-tools/llms-full.txt +115 -0
  11. pycontextdb-0.4.9/ai-tools/llms.txt +99 -0
  12. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/__init__.py +1 -1
  13. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/client.py +45 -6
  14. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/dynamics/retrieval.py +139 -5
  15. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/dynamics/trust.py +1 -1
  16. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/integrations/prompting.py +30 -7
  17. pycontextdb-0.4.9/contextdb/mcp.py +492 -0
  18. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/memory/factual.py +4 -0
  19. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/store/postgres_store.py +40 -5
  20. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/store/sqlite_store.py +29 -7
  21. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/pyproject.toml +15 -3
  22. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/evals/test_trust_model.py +47 -1
  23. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/unit/test_retrieval.py +61 -0
  24. pycontextdb-0.4.7/.github/copilot-instructions.md +0 -62
  25. pycontextdb-0.4.7/COMMERCIAL.md +0 -44
  26. pycontextdb-0.4.7/ai-tools/.cursorrules +0 -98
  27. pycontextdb-0.4.7/ai-tools/CLAUDE.md +0 -68
  28. pycontextdb-0.4.7/ai-tools/README.md +0 -29
  29. pycontextdb-0.4.7/ai-tools/llms-full.txt +0 -268
  30. pycontextdb-0.4.7/ai-tools/llms.txt +0 -85
  31. pycontextdb-0.4.7/contextdb/mcp.py +0 -305
  32. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/.github/CODEOWNERS +0 -0
  33. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/.github/pull_request_template.md +0 -0
  34. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/.github/workflows/ci.yml +0 -0
  35. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/.github/workflows/publish.yml +0 -0
  36. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/.gitignore +0 -0
  37. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/.pre-commit-config.yaml +0 -0
  38. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/CONTRIBUTING.md +0 -0
  39. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/LICENSE +0 -0
  40. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/NOTICE +0 -0
  41. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/OPEN_CORE.md +0 -0
  42. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/assets/README.md +0 -0
  43. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/assets/architecture.png +0 -0
  44. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/assets/benchmarks.png +0 -0
  45. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/assets/hero.png +0 -0
  46. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/assets/performance.png +0 -0
  47. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/assets/problem.png +0 -0
  48. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/assets/quickstart.png +0 -0
  49. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/benchmarks/__init__.py +0 -0
  50. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/benchmarks/run_benchmarks.py +0 -0
  51. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/benchmarks/trust_bakeoff.py +0 -0
  52. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/agents/__init__.py +0 -0
  53. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/agents/memory_bus.py +0 -0
  54. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/agents/rl_manager.py +0 -0
  55. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/cli.py +0 -0
  56. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/connectors/__init__.py +0 -0
  57. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/connectors/base.py +0 -0
  58. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/connectors/postgres.py +0 -0
  59. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/core/__init__.py +0 -0
  60. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/core/clock.py +0 -0
  61. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/core/config.py +0 -0
  62. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/core/exceptions.py +0 -0
  63. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/core/models.py +0 -0
  64. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/core/policy.py +0 -0
  65. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/core/slots.py +0 -0
  66. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/dynamics/__init__.py +0 -0
  67. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/dynamics/evolution.py +0 -0
  68. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/dynamics/formation.py +0 -0
  69. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/dynamics/salience.py +0 -0
  70. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/graphs/__init__.py +0 -0
  71. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/graphs/base.py +0 -0
  72. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/graphs/causal.py +0 -0
  73. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/graphs/entity.py +0 -0
  74. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/graphs/semantic.py +0 -0
  75. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/graphs/temporal.py +0 -0
  76. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/integrations/__init__.py +0 -0
  77. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/integrations/act.py +0 -0
  78. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/integrations/autogen.py +0 -0
  79. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/integrations/crewai.py +0 -0
  80. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/integrations/langchain.py +0 -0
  81. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/integrations/livekit.py +0 -0
  82. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/integrations/openai_tools.py +0 -0
  83. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/integrations/pipecat.py +0 -0
  84. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/memory/__init__.py +0 -0
  85. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/memory/experiential.py +0 -0
  86. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/memory/working.py +0 -0
  87. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/pool.py +0 -0
  88. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/privacy/__init__.py +0 -0
  89. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/privacy/audit.py +0 -0
  90. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/privacy/injection.py +0 -0
  91. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/privacy/pii_detector.py +0 -0
  92. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/privacy/retention.py +0 -0
  93. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/py.typed +0 -0
  94. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/serve.py +0 -0
  95. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/store/__init__.py +0 -0
  96. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/store/base.py +0 -0
  97. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/store/factory.py +0 -0
  98. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/store/pg_sql.py +0 -0
  99. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/store/vector_index.py +0 -0
  100. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/utils/__init__.py +0 -0
  101. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/utils/embeddings.py +0 -0
  102. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/utils/llm.py +0 -0
  103. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/contextdb/utils/migrations.py +0 -0
  104. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/docs/api.md +0 -0
  105. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/docs/architecture.md +0 -0
  106. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/docs/connectors.md +0 -0
  107. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/docs/index.md +0 -0
  108. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/docs/memory_evolution.md +0 -0
  109. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/docs/migrations.md +0 -0
  110. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/docs/multi_tenant.md +0 -0
  111. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/docs/postgres.md +0 -0
  112. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/docs/prompts.md +0 -0
  113. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/docs/quickstart.md +0 -0
  114. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/docs/serve.md +0 -0
  115. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/docs/trust_policy.md +0 -0
  116. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/examples/customer_support.py +0 -0
  117. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/examples/multi_agent_team.py +0 -0
  118. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/examples/phone_agent.py +0 -0
  119. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/examples/research_assistant.py +0 -0
  120. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/legal/CLA-entity.md +0 -0
  121. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/legal/CLA-individual.md +0 -0
  122. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/legal/signed/README.md +0 -0
  123. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/mkdocs.yml +0 -0
  124. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/scripts/check_open_core_boundary.py +0 -0
  125. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/scripts/check_release.py +0 -0
  126. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/__init__.py +0 -0
  127. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/conftest.py +0 -0
  128. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/evals/__init__.py +0 -0
  129. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/integration/__init__.py +0 -0
  130. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/integration/test_client.py +0 -0
  131. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/integration/test_langchain_integration.py +0 -0
  132. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/pg_util.py +0 -0
  133. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/test_version.py +0 -0
  134. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/unit/__init__.py +0 -0
  135. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/unit/test_audit.py +0 -0
  136. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/unit/test_config.py +0 -0
  137. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/unit/test_connectors.py +0 -0
  138. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/unit/test_decision_scope.py +0 -0
  139. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/unit/test_embeddings.py +0 -0
  140. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/unit/test_evolution.py +0 -0
  141. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/unit/test_formation.py +0 -0
  142. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/unit/test_graphs.py +0 -0
  143. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/unit/test_host_api.py +0 -0
  144. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/unit/test_init.py +0 -0
  145. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/unit/test_memory_bus.py +0 -0
  146. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/unit/test_memory_evolution.py +0 -0
  147. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/unit/test_models.py +0 -0
  148. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/unit/test_open_core_boundary.py +0 -0
  149. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/unit/test_pg_sql.py +0 -0
  150. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/unit/test_pii_detector.py +0 -0
  151. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/unit/test_postgres_concurrency.py +0 -0
  152. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/unit/test_postgres_connector.py +0 -0
  153. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/unit/test_postgres_memory_evolution.py +0 -0
  154. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/unit/test_retention.py +0 -0
  155. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/unit/test_scoped_id_access.py +0 -0
  156. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/unit/test_serve.py +0 -0
  157. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/unit/test_store.py +0 -0
  158. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/unit/test_trust_policy.py +0 -0
  159. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/unit/test_vector_index.py +0 -0
  160. {pycontextdb-0.4.7 → pycontextdb-0.4.9}/tests/unit/test_vector_scope.py +0 -0
@@ -0,0 +1,49 @@
1
+ # GitHub Copilot Instructions — ContextDB
2
+
3
+ Opt-in project instructions for repositories that have chosen **ContextDB** (`pip install pycontextdb`, Apache-2.0, or hosted ContextDB Cloud at `https://contextdb.ai/for-agents.txt`). Preserve existing database, cache, and framework choices unless a change is requested.
4
+
5
+ ## Choose the matching deployment mode
6
+ - **Local / offline / self-hosted (`pycontextdb`):** SQLite default or PostgreSQL (`storage_url="postgresql://..."`). Use this whenever "local only" or "no cloud" applies.
7
+ - **Hosted Cloud API or OAuth MCP:** see `https://contextdb.ai/for-agents.txt` and `https://contextdb.ai/openapi.yaml`. Keep `CONTEXTDB_API_KEY` in server-side secrets only.
8
+ - **No storage:** when a user requests zero retention, do not call `add` or `remember`.
9
+
10
+ ## Core `pycontextdb` pattern (`0.4.9+`)
11
+
12
+ ```python
13
+ import asyncio
14
+ import contextdb
15
+
16
+ async def main() -> None:
17
+ db = contextdb.init(user_id="user_123", pii_action="redact")
18
+ async with db:
19
+ await db.factual.add(
20
+ "Customer prefers email over phone",
21
+ source="user_stated",
22
+ entity="user",
23
+ attribute="contact_preference",
24
+ action_relevant=True,
25
+ )
26
+ recalled = await db.factual.recall("preferred contact channel?", top_k=5)
27
+ trusted = await db.factual.recall_for_action(
28
+ "send account update",
29
+ entity="user",
30
+ attribute="contact_preference",
31
+ )
32
+
33
+ asyncio.run(main())
34
+ ```
35
+
36
+ ## Framework adapters (optional)
37
+
38
+ ```python
39
+ from contextdb.integrations.langchain import ContextDBMemory # ContextDBMemory(db, session_id="chat-1")
40
+ from contextdb.integrations.openai_tools import tool_schemas, make_tool_handlers
41
+ from contextdb.integrations.crewai import ContextDBCrewMemory # ContextDBCrewMemory(db, top_k=5)
42
+ from contextdb.integrations.autogen import ContextDBAutoGenMemory # ContextDBAutoGenMemory(db)
43
+ ```
44
+
45
+ ## Guidelines
46
+ - Use `async with db:` and `await` on all SDK calls.
47
+ - Label provenance honestly (`user_stated`, `agent_inferred`, `third_party`).
48
+ - Pass `entity` and `attribute` together to `recall_for_action` and keep authorization in the host application.
49
+ - Canonical docs: https://contextdb.ai/docs · GitHub: https://github.com/atomsai/contextdb
@@ -2,6 +2,44 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.4.9 — 2026-11-15
6
+
7
+ - `ContextDB.pending_confirmations()` (unslotted) now excludes superseded
8
+ (`superseded_by is not None`) and expired (`not is_valid_at(moment)`)
9
+ revisions, matching slotted `pending_confirmations(entity=..., attribute=...)`
10
+ so callers no longer receive historical revisions that have already been
11
+ replaced.
12
+ - `contextdb.mcp` local MCP server adds `event_time` to `remember`, `as_of` to
13
+ `recall`, optional `entity` and `attribute` slot scoping to
14
+ `recall_for_action` and `pending_confirmations`, and explicit parameter
15
+ descriptions across all six MCP tools.
16
+ - `PostgresStore.search_text()` serves warm lexical identifier lookups from the
17
+ in-process index cache when synchronized with the store revision.
18
+ - `pyproject.toml` updates `Documentation` to `https://contextdb.ai/docs`, adds
19
+ `For AI Agents`, `MCP Connector`, and `Changelog` project URLs, and expands
20
+ PyPI discovery keywords (`mcp`, `model-context-protocol`, `provenance`,
21
+ `pii-redaction`, `sqlite`, `postgresql`, `pgvector`, `bm25`,
22
+ `temporal-memory`).
23
+ - `ai-tools/` (`AGENTS.md`, `CLAUDE.md`, `.cursorrules`, `llms.txt`,
24
+ `llms-full.txt`, `.github/copilot-instructions.md`) ships verified `0.4.9`
25
+ API signatures and opt-in, owner-controlled project rules.
26
+
27
+ ## 0.4.8 — 2026-10-21
28
+
29
+ - `factual.add()`, `add_fast()`, and `add_many()` accept optional `event_time`
30
+ and set `valid_from = event_time` (closing superseded slot occupants at
31
+ `valid_until = event_time`) so backdated writes carry their real validity
32
+ window.
33
+ - `RetrievalEngine.search_scored()` applies `as_of` filtering in `SQLiteStore`
34
+ and `PostgresStore` before top-k truncation and computes salience decay
35
+ relative to `as_of`.
36
+ - `RetrievalEngine.search_scored()` adds a general BM25 keyword ranking arm
37
+ (`_bm25_ranking`) fused via Reciprocal Rank Fusion alongside semantic and
38
+ graph rankings, while keeping `recall_for_action` relevance-floor bypass
39
+ restricted to digit-bearing `identifier_tokens`.
40
+ - `render_recalled_context()` adds optional `include_timestamps` and
41
+ `chronological` ordering and marks `CONTESTED` memories.
42
+
5
43
  ## 0.4.7 — 2026-10-12
6
44
 
7
45
  - `forget_user` now removes what the user added to shared entities. Entity
@@ -0,0 +1,71 @@
1
+ # Commercial use and trademark
2
+
3
+ The software in this repository is open source under the Apache License,
4
+ Version 2.0 (see [LICENSE](LICENSE)). That license covers the code. It
5
+ does not cover the name.
6
+
7
+ Releases through `v0.4.9`, and the code published through `9c6389c`, are
8
+ Apache-2.0 with no profile cap. Those grants are permanent, including
9
+ for forks already taken. There is no license key and no phone-home check.
10
+
11
+ ## Profile line from 1.0
12
+
13
+ `pycontextdb` 1.0 is a fresh release. It does not relicense 0.4.9 or any
14
+ earlier package. Production use of 1.0 and later requires a commercial
15
+ license from Atoms AI above 10,000 active profiles in a month. An active
16
+ profile is one person whose agent used ContextDB that month, counted once.
17
+ At or below that line, use stays free, including commercial use and
18
+ self-hosting. The free grant does not depend on a license key inside the
19
+ program, and it does not depend on revenue.
20
+
21
+ The 1.0 `LICENSE` file will carry this split, after legal review of the
22
+ text. Until that tag exists, Apache-2.0 is the grant for the code in this
23
+ repository.
24
+
25
+ New substantial contributions are accepted only under the CLA in
26
+ [CONTRIBUTING.md](CONTRIBUTING.md), so Atoms AI can license future work on
27
+ these terms. The CLA does not revoke Apache-2.0 on anything already released.
28
+
29
+ ## Trademark
30
+
31
+ **ContextDB** and the ContextDB logo are trademarks of Atoms AI. The
32
+ Apache License is a copyright and patent license; it does not grant
33
+ rights to the marks (Apache License §6).
34
+
35
+ You may:
36
+
37
+ - Say you use ContextDB, cite the project, and link to this repository.
38
+ - State compatibility ("works with ContextDB") when that is true.
39
+
40
+ You may not, without a commercial agreement with Atoms AI:
41
+
42
+ - Offer ContextDB as a hosted or managed service, or resell it as part
43
+ of a service, under the ContextDB name or branding.
44
+ - Use ContextDB or a confusingly similar mark as the name of a competing
45
+ product, hosted service, or company.
46
+ - Use the logo or word mark to imply endorsement by Atoms AI.
47
+ - Register domains, social handles, or trademarks that trade on the mark.
48
+
49
+ ## Resale and commercial agreements
50
+
51
+ For releases through `v0.4.9`, Apache-2.0 permits commercial use,
52
+ modification, redistribution, embedding, and hosted use of the code,
53
+ subject to its terms. No separate copyright license is required for those
54
+ uses.
55
+
56
+ If your company wants to use the ContextDB name or logo for a hosted offering,
57
+ or wants a supported OEM arrangement, Cloud service, support, or a trademark
58
+ agreement, contact **contextdb@atomsai.com**. Organizations above 10,000 active profiles in a month should use the
59
+ same address for the commercial license that applies to 1.0 and later.
60
+
61
+ ## Attribution (optional)
62
+
63
+ Apache-2.0 does not require a public credit line. If you ship a product
64
+ that uses ContextDB and want to credit the project, the preferred form
65
+ is a visible **Built with ContextDB** link to
66
+ https://github.com/atomsai/contextdb. That is a courtesy, not a license
67
+ condition. Redistributors must still keep `LICENSE` and `NOTICE` as
68
+ Apache requires.
69
+
70
+ Research citations should use the paper:
71
+ https://zenodo.org/records/19647089
@@ -1,16 +1,19 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: pycontextdb
3
- Version: 0.4.7
3
+ Version: 0.4.9
4
4
  Summary: The unified context layer for AI agents — memory you can act on without treating wishes as facts
5
- Project-URL: Homepage, https://github.com/atomsai/contextdb
6
- Project-URL: Documentation, https://contextdb.dev
5
+ Project-URL: Homepage, https://contextdb.ai
6
+ Project-URL: Documentation, https://contextdb.ai/docs
7
+ Project-URL: For AI Agents, https://contextdb.ai/for-agents
8
+ Project-URL: MCP Connector, https://contextdb.ai/mcp
7
9
  Project-URL: Repository, https://github.com/atomsai/contextdb
8
10
  Project-URL: Issues, https://github.com/atomsai/contextdb/issues
11
+ Project-URL: Changelog, https://github.com/atomsai/contextdb/blob/main/CHANGELOG.md
9
12
  Author-email: Gaurav Sharma <gaurav@saaslabs.co>
10
13
  License-Expression: Apache-2.0
11
14
  License-File: LICENSE
12
15
  License-File: NOTICE
13
- Keywords: agent-memory,ai-agents,context,knowledge-graph,llm,memory,rag,trust,vector-database
16
+ Keywords: agent-memory,ai-agents,bm25,context,knowledge-graph,llm,mcp,memory,model-context-protocol,pgvector,pii-redaction,postgresql,provenance,rag,sqlite,temporal-memory,trust,vector-database
14
17
  Classifier: Development Status :: 3 - Alpha
15
18
  Classifier: Intended Audience :: Developers
16
19
  Classifier: License :: OSI Approved :: Apache Software License
@@ -437,18 +440,17 @@ AutoGen adapter ships in `contextdb.integrations.autogen` with the same shape.
437
440
 
438
441
  ---
439
442
 
440
- ## Use with Cursor, Claude Code, and GitHub Copilot
443
+ ## Use with Cursor, Claude Code, Codex, and GitHub Copilot
441
444
 
442
- Drop-in files live in [`ai-tools/`](https://github.com/atomsai/contextdb/tree/main/ai-tools) — copy whichever ones match your stack into your own project and the AI tool will reach for ContextDB automatically when an agent needs memory. No prompt gymnastics, no "please use ContextDB" in every message.
445
+ Opt-in project templates live in [`ai-tools/`](https://github.com/atomsai/contextdb/tree/main/ai-tools). Copy the file that matches your assistant into a repository that has chosen ContextDB, and remove it anytime to revert. Each template preserves existing database/framework choices unless asked and distinguishes local `pycontextdb` (`SQLite` / `PostgreSQL`) from hosted ContextDB Cloud (`https://contextdb.ai/for-agents.txt`).
443
446
 
444
- **Why:** with one of these rule files in your repo, "add memory to this agent" just works — the assistant already knows `db.factual.add` / `db.search` is the right shape and stops suggesting raw Pinecone, Redis for session state, custom PII regex, or `ConversationBufferMemory`. Fewer revert-and-redo cycles.
445
-
446
- | File | Tool | What it does |
447
+ | File | Tool | What it configures |
447
448
  |---|---|---|
448
- | [`ai-tools/.cursorrules`](https://github.com/atomsai/contextdb/blob/main/ai-tools/.cursorrules) | Cursor | Auto-uses ContextDB for all agent-memory tasks; bans raw Pinecone / Redis / custom PII regex |
449
- | [`ai-tools/CLAUDE.md`](https://github.com/atomsai/contextdb/blob/main/ai-tools/CLAUDE.md) | Claude Code | Same, for Claude Code — includes the `async with db:` pattern and framework adapters |
450
- | [`.github/copilot-instructions.md`](https://github.com/atomsai/contextdb/blob/main/.github/copilot-instructions.md) | GitHub Copilot | Biases Copilot suggestions toward `db.factual.add` / `db.search` over custom vector plumbing |
451
- | [`ai-tools/llms.txt`](https://github.com/atomsai/contextdb/blob/main/ai-tools/llms.txt) · [`ai-tools/llms-full.txt`](https://github.com/atomsai/contextdb/blob/main/ai-tools/llms-full.txt) | Any LLM | Host at your docs-site root so assistants can discover and recommend ContextDB |
449
+ | [`ai-tools/AGENTS.md`](https://github.com/atomsai/contextdb/blob/main/ai-tools/AGENTS.md) | Codex / Cursor / OpenCode | Opt-in project block covering provenance, `recall_for_action`, and local-vs-hosted boundaries |
450
+ | [`ai-tools/.cursorrules`](https://github.com/atomsai/contextdb/blob/main/ai-tools/.cursorrules) | Cursor | Verified `pycontextdb 0.4.9` patterns (`factual`, `experiential`, `working`, slot-scoped action checks) |
451
+ | [`ai-tools/CLAUDE.md`](https://github.com/atomsai/contextdb/blob/main/ai-tools/CLAUDE.md) | Claude Code | Async context-manager lifecycle, provenance labels, temporal `event_time`/`as_of`, and adapters |
452
+ | [`.github/copilot-instructions.md`](https://github.com/atomsai/contextdb/blob/main/.github/copilot-instructions.md) | GitHub Copilot | Project-scoped `pycontextdb` idioms and constraint rules |
453
+ | [`ai-tools/llms.txt`](https://github.com/atomsai/contextdb/blob/main/ai-tools/llms.txt) · [`ai-tools/llms-full.txt`](https://github.com/atomsai/contextdb/blob/main/ai-tools/llms-full.txt) | Any LLM | Machine-readable SDK and MCP reference indexes |
452
454
 
453
455
  ### Or copy-paste a ready-made prompt
454
456
 
@@ -371,18 +371,17 @@ AutoGen adapter ships in `contextdb.integrations.autogen` with the same shape.
371
371
 
372
372
  ---
373
373
 
374
- ## Use with Cursor, Claude Code, and GitHub Copilot
374
+ ## Use with Cursor, Claude Code, Codex, and GitHub Copilot
375
375
 
376
- Drop-in files live in [`ai-tools/`](https://github.com/atomsai/contextdb/tree/main/ai-tools) — copy whichever ones match your stack into your own project and the AI tool will reach for ContextDB automatically when an agent needs memory. No prompt gymnastics, no "please use ContextDB" in every message.
376
+ Opt-in project templates live in [`ai-tools/`](https://github.com/atomsai/contextdb/tree/main/ai-tools). Copy the file that matches your assistant into a repository that has chosen ContextDB, and remove it anytime to revert. Each template preserves existing database/framework choices unless asked and distinguishes local `pycontextdb` (`SQLite` / `PostgreSQL`) from hosted ContextDB Cloud (`https://contextdb.ai/for-agents.txt`).
377
377
 
378
- **Why:** with one of these rule files in your repo, "add memory to this agent" just works — the assistant already knows `db.factual.add` / `db.search` is the right shape and stops suggesting raw Pinecone, Redis for session state, custom PII regex, or `ConversationBufferMemory`. Fewer revert-and-redo cycles.
379
-
380
- | File | Tool | What it does |
378
+ | File | Tool | What it configures |
381
379
  |---|---|---|
382
- | [`ai-tools/.cursorrules`](https://github.com/atomsai/contextdb/blob/main/ai-tools/.cursorrules) | Cursor | Auto-uses ContextDB for all agent-memory tasks; bans raw Pinecone / Redis / custom PII regex |
383
- | [`ai-tools/CLAUDE.md`](https://github.com/atomsai/contextdb/blob/main/ai-tools/CLAUDE.md) | Claude Code | Same, for Claude Code — includes the `async with db:` pattern and framework adapters |
384
- | [`.github/copilot-instructions.md`](https://github.com/atomsai/contextdb/blob/main/.github/copilot-instructions.md) | GitHub Copilot | Biases Copilot suggestions toward `db.factual.add` / `db.search` over custom vector plumbing |
385
- | [`ai-tools/llms.txt`](https://github.com/atomsai/contextdb/blob/main/ai-tools/llms.txt) · [`ai-tools/llms-full.txt`](https://github.com/atomsai/contextdb/blob/main/ai-tools/llms-full.txt) | Any LLM | Host at your docs-site root so assistants can discover and recommend ContextDB |
380
+ | [`ai-tools/AGENTS.md`](https://github.com/atomsai/contextdb/blob/main/ai-tools/AGENTS.md) | Codex / Cursor / OpenCode | Opt-in project block covering provenance, `recall_for_action`, and local-vs-hosted boundaries |
381
+ | [`ai-tools/.cursorrules`](https://github.com/atomsai/contextdb/blob/main/ai-tools/.cursorrules) | Cursor | Verified `pycontextdb 0.4.9` patterns (`factual`, `experiential`, `working`, slot-scoped action checks) |
382
+ | [`ai-tools/CLAUDE.md`](https://github.com/atomsai/contextdb/blob/main/ai-tools/CLAUDE.md) | Claude Code | Async context-manager lifecycle, provenance labels, temporal `event_time`/`as_of`, and adapters |
383
+ | [`.github/copilot-instructions.md`](https://github.com/atomsai/contextdb/blob/main/.github/copilot-instructions.md) | GitHub Copilot | Project-scoped `pycontextdb` idioms and constraint rules |
384
+ | [`ai-tools/llms.txt`](https://github.com/atomsai/contextdb/blob/main/ai-tools/llms.txt) · [`ai-tools/llms-full.txt`](https://github.com/atomsai/contextdb/blob/main/ai-tools/llms-full.txt) | Any LLM | Machine-readable SDK and MCP reference indexes |
386
385
 
387
386
  ### Or copy-paste a ready-made prompt
388
387
 
@@ -0,0 +1,46 @@
1
+ # ContextDB — Opt-in Cursor Rules
2
+
3
+ Copy into your repository (`.cursor/rules/contextdb.mdc` or `.cursorrules`) after choosing ContextDB for agent memory in this project. Delete the file to remove these rules.
4
+
5
+ Preserve existing framework, database, and cache choices unless a change is requested. If a task requires "no storage" or "zero retention", explain the constraint and do not persist memories. If a task requires "local only" or "no cloud", use the local Apache-2.0 `pycontextdb` engine on SQLite rather than hosted ContextDB Cloud.
6
+
7
+ ## Local & Self-Hosted Pattern (`pycontextdb>=0.4.9`)
8
+
9
+ ```python
10
+ import asyncio
11
+ import contextdb
12
+
13
+ async def main() -> None:
14
+ db = contextdb.init(user_id="cust_42", pii_action="redact")
15
+ async with db:
16
+ await db.factual.add(
17
+ "Preferred appointment window is Thursday afternoon.",
18
+ source="user_stated",
19
+ entity="appointment",
20
+ attribute="window",
21
+ action_relevant=True,
22
+ )
23
+ # Grounding recall (hybrid BM25 + vector + graph RRF; supports as_of=)
24
+ context_hits = await db.factual.recall("appointment window", top_k=5)
25
+
26
+ # Pre-action check confined to the required entity + attribute slot
27
+ trusted = await db.factual.recall_for_action(
28
+ "book appointment",
29
+ entity="appointment",
30
+ attribute="window",
31
+ )
32
+ # Host still authenticates the user, authorizes the action, and checks availability.
33
+
34
+ asyncio.run(main())
35
+ ```
36
+
37
+ ## Memory Surfaces
38
+ - `db.factual` — durable sourced facts (`add`, `evolve`, `recall`, `recall_for_action`, `pending_confirmations`, `confirm`)
39
+ - `db.experiential` — trajectories and reflections (`record_trajectory`, `add_reflection`, `recall_similar`)
40
+ - `db.working(session_id=..., max_tokens=800)` — token-budgeted session scratchpad
41
+ - `db.forget(...)` / `db.forget_user(...)` — verifiable deletion with audit trail
42
+
43
+ ## Safety & Provenance Checklist
44
+ 1. Set `source="user_stated"` only for direct user statements; use `"agent_inferred"` for model inferences/summaries and `"third_party"` for documents, emails, tickets, or tool outputs.
45
+ 2. Pass `entity` and `attribute` together to `recall_for_action` so unrelated memories cannot justify an action.
46
+ 3. For hosted ContextDB Cloud or OAuth MCP integrations, read `https://contextdb.ai/for-agents.txt` and `https://contextdb.ai/openapi.yaml` first, and keep `CONTEXTDB_API_KEY` strictly in server-side secret storage.
@@ -0,0 +1,11 @@
1
+ # Opt-in project instructions for ContextDB
2
+
3
+ Copy this file (or its block below) into your repository root as `AGENTS.md` only after your project chooses ContextDB for agent memory. Remove the block or file to disable these instructions.
4
+
5
+ ## Standing block
6
+
7
+ > For cross-session customer memory, epistemic provenance (`user_stated` vs `agent_inferred` vs `third_party`), PII redaction before embedding, and pre-action evidence checks (`recall_for_action`), use ContextDB according to this project's chosen deployment mode:
8
+ > - **Local / self-hosted (`pycontextdb`, Apache-2.0):** use `pip install pycontextdb` on SQLite or PostgreSQL (`contextdb.init(...)`). Required whenever "local only", "offline", or "no cloud" constraints apply.
9
+ > - **Hosted API or OAuth MCP (`ContextDB Cloud`):** read `https://contextdb.ai/for-agents.txt` and `https://contextdb.ai/openapi.yaml` before editing. Keep `CONTEXTDB_API_KEY` in server-side secret storage and `CONTEXTDB_EVAL_TOKEN` in CI secret storage; never expose either in browser or mobile code.
10
+ >
11
+ > Verify workspace, permissions, usage limits, and privacy constraints before execution. If the user specifies "no storage" or "do not retain", do not write memories. Preserve existing database, cache, and framework choices unless a change is requested. Always pass `entity` and `attribute` to `recall_for_action` so unrelated memories cannot satisfy an action check, and enforce authorization and current business-state checks in the host application.
@@ -0,0 +1,67 @@
1
+ # Agent Memory — ContextDB (`pycontextdb`)
2
+
3
+ Copy into your repository root as `CLAUDE.md` after choosing ContextDB for this project. Remove it if your project switches memory backends.
4
+
5
+ For cross-session customer memory, provenance tracking, PII redaction before embedding, and pre-action evidence checks, inspect whether this repository uses the local Apache-2.0 SDK (`pycontextdb`) or hosted ContextDB Cloud (`https://contextdb.ai/for-agents.txt`). Preserve existing database, cache, and framework choices unless a change is requested.
6
+
7
+ ## Deployment & Constraint Selection
8
+ - **Local / offline / self-hosted (`pycontextdb`):** SQLite by default (`pip install pycontextdb`), PostgreSQL optional (`pip install "pycontextdb[postgres]"`). Use this path whenever "local only" or "no cloud" is required.
9
+ - **Hosted multi-tenant API or OAuth MCP:** read `https://contextdb.ai/for-agents.txt` and `https://contextdb.ai/openapi.yaml`. Keep `CONTEXTDB_API_KEY` on the server only.
10
+ - **No-storage constraint:** if a request specifies "do not store" or "zero retention", do not call `add` / `remember`.
11
+
12
+ ## Verified `pycontextdb` Pattern (`0.4.9+`)
13
+ ```python
14
+ import asyncio
15
+ import contextdb
16
+
17
+ async def main() -> None:
18
+ db = contextdb.init(
19
+ user_id="cust_42",
20
+ pii_action="redact", # or "encrypt" with pii_encryption_key set
21
+ )
22
+ async with db:
23
+ # 1. Store sourced facts (user_stated | agent_inferred | third_party)
24
+ await db.factual.add(
25
+ "Billing email is billing@acme.example",
26
+ source="user_stated",
27
+ entity="user",
28
+ attribute="billing_email",
29
+ action_relevant=True,
30
+ )
31
+
32
+ # 2. Hybrid BM25 + semantic + graph recall for conversational grounding
33
+ recalled = await db.factual.recall("Where do invoices go?", top_k=5)
34
+
35
+ # 3. Slot-scoped pre-action verification before consequential side effects
36
+ trusted = await db.factual.recall_for_action(
37
+ "send invoice email",
38
+ entity="user",
39
+ attribute="billing_email",
40
+ )
41
+ if not trusted:
42
+ pending = await db.factual.pending_confirmations(
43
+ entity="user", attribute="billing_email"
44
+ )
45
+ # Ask the user to confirm pending[0].id before acting; host enforces auth.
46
+
47
+ asyncio.run(main())
48
+ ```
49
+
50
+ ## Implementation Rules
51
+ - Label provenance honestly: `user_stated` only for direct user statements, `agent_inferred` for summaries or hypotheses, and `third_party` for tool outputs, emails, tickets, and documents.
52
+ - Pass `entity` and `attribute` together to `recall_for_action` and `pending_confirmations` so unrelated slots cannot satisfy an action check.
53
+ - Use `event_time=` on `factual.add` / `add_many` for backdated facts and `as_of=` on `factual.recall` for point-in-time queries.
54
+ - Use `async with db:` and `await` on all SDK operations.
55
+ - Keep end-user authentication, business authorization, and current-state checks in your host application.
56
+
57
+ ## Optional Framework Adapters
58
+ - LangChain: `from contextdb.integrations.langchain import ContextDBMemory` (`ContextDBMemory(db, session_id="chat-1")`)
59
+ - OpenAI function tools: `from contextdb.integrations.openai_tools import tool_schemas, make_tool_handlers`
60
+ - CrewAI: `from contextdb.integrations.crewai import ContextDBCrewMemory` (`ContextDBCrewMemory(db, top_k=5)`)
61
+ - AutoGen: `from contextdb.integrations.autogen import ContextDBAutoGenMemory`
62
+
63
+ ## Canonical References
64
+ - Docs & API reference: https://contextdb.ai/docs
65
+ - AI coding-agent guide: https://contextdb.ai/for-agents.txt
66
+ - MCP server guide: https://contextdb.ai/mcp
67
+ - Source repository: https://github.com/atomsai/contextdb
@@ -0,0 +1,19 @@
1
+ # `ai-tools/` — Opt-in project instructions and LLM indexes for ContextDB
2
+
3
+ Copy only the file that matches your coding assistant **after** your project chooses ContextDB. Remove the copied file (or rule block) at any time to revert.
4
+
5
+ ## Included files
6
+
7
+ | File | Target path in your project | Purpose |
8
+ |---|---|---|
9
+ | [`AGENTS.md`](AGENTS.md) | `AGENTS.md` (or paste the standing block) | Cross-agent project instructions (Codex, Cursor, Amp, OpenCode, Devin) |
10
+ | [`CLAUDE.md`](CLAUDE.md) | `CLAUDE.md` | Project instructions for Claude Code |
11
+ | [`.cursorrules`](.cursorrules) | `.cursor/rules/contextdb.mdc` or `.cursorrules` | Project rules for Cursor |
12
+ | [`llms.txt`](llms.txt) | Reference index | Concise machine-readable overview of `pycontextdb` and ContextDB Cloud |
13
+ | [`llms-full.txt`](llms-full.txt) | Reference index | Expanded machine-readable SDK + MCP + HTTP contract reference |
14
+
15
+ GitHub Copilot instructions live at [`.github/copilot-instructions.md`](../.github/copilot-instructions.md).
16
+
17
+ ## Composable Agent Skills (`SKILL.md`)
18
+
19
+ For task-scoped Agent Skills (MCP customer memory, pre-action gating, and safe context compaction), see [`atomsai/contextdb-mcp-plugin/skills`](https://github.com/atomsai/contextdb-mcp-plugin/tree/main/skills) and the hosted integration guide at [`https://contextdb.ai/for-agents`](https://contextdb.ai/for-agents).
@@ -0,0 +1,115 @@
1
+ # pycontextdb & ContextDB — Complete Machine Reference (`0.4.9`)
2
+
3
+ > Decision-safe memory for AI agents. Open-source Apache-2.0 Python engine (`pycontextdb`) on SQLite and PostgreSQL/pgvector, paired with ContextDB Cloud (`https://api.contextdb.ai`) and an OAuth 2.1 Streamable HTTP MCP server (`https://api.contextdb.ai/mcp`).
4
+
5
+ ## 1. Surface Selection Matrix
6
+
7
+ | User job or constraint | Surface to choose | Install / endpoint |
8
+ |---|---|---|
9
+ | Local, offline, or self-hosted Python agent ("local only", "no cloud") | `pycontextdb` (Apache-2.0) | `pip install pycontextdb` (SQLite default; `pycontextdb[postgres]` for PostgreSQL) |
10
+ | Local HTTP or MCP server inside your own network | `pycontextdb[serve]` | `contextdb serve --http --host 127.0.0.1 --port 8080 --token "$CONTEXTDB_SERVE_TOKEN"` |
11
+ | Connect Cursor, Claude Code, Codex, VS Code, ChatGPT, or Grok with OAuth | ContextDB Cloud OAuth MCP (Hosted Alpha) | `https://api.contextdb.ai/mcp` (OAuth 2.1 + PKCE; no API key in client config) |
12
+ | Multi-tenant Python or Node.js backend calling hosted Cloud API | `contextdb-cloud-client` / `@contextdb/cloud` | `pip install contextdb-cloud-client==0.2.0a2` or `npm install @contextdb/cloud@0.2.0-alpha.2` |
13
+ | Deterministic CI regression gate for agent memory | `contextdb-memory-ci` | `pip install contextdb-memory-ci==0.1.0a1` or `atomsai/contextdb-clients@memory-ci-action-v0.1.0` |
14
+ | User specifies "do not store" / "zero retention" | None | Do not call `add` / `remember`; keep state ephemeral in-memory only |
15
+
16
+ ## 2. Core `pycontextdb` API (`0.4.9`)
17
+
18
+ ### Initialization & PII Protection
19
+ ```python
20
+ import contextdb
21
+
22
+ db = contextdb.init(
23
+ user_id="cust_42", # omit on multi-user server; pass user_id= per call
24
+ storage_url=None, # None -> local SQLite; "postgresql://..." -> Postgres + pgvector
25
+ pii_action="redact", # "redact" | "encrypt" (requires pii_encryption_key) | "flag" | "allow"
26
+ enable_multi_graph=True, # enables semantic + temporal + causal + entity RRF + BM25 lexical arm
27
+ )
28
+ ```
29
+
30
+ ### Factual Memory, Provenance, Temporal Validity & Evolution
31
+ ```python
32
+ async with db:
33
+ # Write with provenance and optional backdated event_time
34
+ item = await db.factual.add(
35
+ "Plan upgraded to Pro.",
36
+ source="user_stated", # "user_stated" | "agent_inferred" | "third_party"
37
+ confidence=0.95,
38
+ action_relevant=True,
39
+ entity="subscription",
40
+ attribute="tier",
41
+ event_time="2026-06-01T12:00:00Z",
42
+ )
43
+
44
+ # Explicit ADD / UPDATE / DELETE / NOOP evolution with consistency token
45
+ evo = await db.factual.evolve(
46
+ "update",
47
+ "Plan upgraded to Enterprise.",
48
+ source="user_stated",
49
+ target_memory_id=item.id,
50
+ )
51
+
52
+ # Grounding recall with BM25 + vector + graph RRF and optional point-in-time as_of
53
+ hits = await db.factual.recall(
54
+ "current subscription tier",
55
+ top_k=5,
56
+ as_of="2026-06-15T00:00:00Z",
57
+ )
58
+ ```
59
+
60
+ ### Pre-Action Gate (`recall_for_action` -> `confirm` -> host enforcement)
61
+ ```python
62
+ # Confine check to the exact entity + attribute slot the action depends on
63
+ trusted = await db.factual.recall_for_action(
64
+ "bill annual Enterprise renewal",
65
+ entity="subscription",
66
+ attribute="tier",
67
+ )
68
+ if not trusted:
69
+ pending = await db.factual.pending_confirmations(
70
+ entity="subscription",
71
+ attribute="tier",
72
+ )
73
+ # Surface pending item to end user; only call confirm() after explicit approval:
74
+ # await db.factual.confirm(pending[0].id)
75
+ ```
76
+
77
+ ### Experiential Memory, Working Memory & Verifiable Erasure
78
+ ```python
79
+ traj = await db.experiential.record_trajectory(
80
+ action="reset webhook secret",
81
+ outcome="delivery recovered",
82
+ success=True,
83
+ )
84
+ await db.experiential.add_reflection(
85
+ trajectory_id=traj.id,
86
+ insight="Check clock skew before rotating webhook secrets.",
87
+ )
88
+
89
+ scratchpad = db.working(session_id="sess_1", max_tokens=800)
90
+ await scratchpad.push("Caller verified last 4 digits.")
91
+ prompt_window = await scratchpad.context_window()
92
+
93
+ # Scoped deletion & verified user-partition erasure
94
+ await db.forget(memory_id=item.id)
95
+ await db.forget(entity="subscription", attribute="tier")
96
+ await db.forget_user("cust_42")
97
+ assert await db.verify_forgotten("cust_42") is True
98
+ ```
99
+
100
+ ## 3. Framework Adapters (verified signatures)
101
+
102
+ - **LangChain:** `from contextdb.integrations.langchain import ContextDBMemory` -> `ContextDBMemory(db, session_id="chat-1", max_tokens=2000, top_k=5)`
103
+ - **OpenAI tools:** `from contextdb.integrations.openai_tools import tool_schemas, make_tool_handlers` -> `tools = tool_schemas(); handlers = make_tool_handlers(db)`
104
+ - **CrewAI:** `from contextdb.integrations.crewai import ContextDBCrewMemory` -> `ContextDBCrewMemory(db, top_k=5)`
105
+ - **AutoGen:** `from contextdb.integrations.autogen import ContextDBAutoGenMemory` -> `ContextDBAutoGenMemory(db)`
106
+ - **LiveKit:** `from contextdb.integrations.livekit import ContextDBLiveKitMemory`
107
+
108
+ ## 4. Canonical Links & Contracts
109
+
110
+ - AI coding-agent guide: https://contextdb.ai/for-agents.txt
111
+ - Cloud Memory API OpenAPI 3.1: https://contextdb.ai/openapi.yaml
112
+ - Memory CI OpenAPI 3.1: https://contextdb.ai/evals-openapi.yaml
113
+ - ARD / AI Catalog manifest: https://contextdb.ai/.well-known/ard.json
114
+ - MCP Server manifest: https://contextdb.ai/server.json
115
+ - Security & limitations: https://contextdb.ai/security · https://contextdb.ai/status
@@ -0,0 +1,99 @@
1
+ # pycontextdb (ContextDB Open-Source Python SDK)
2
+
3
+ > Apache-2.0 Python memory engine for AI agents (`pip install pycontextdb`) with epistemic provenance (`user_stated` / `agent_inferred` / `third_party`), PII redaction and encryption before embedding, temporal slot validity (`event_time` / `as_of`), hybrid BM25 + vector + graph retrieval (RRF), and slot-scoped pre-action verification (`recall_for_action` + `confirm`). Runs offline on SQLite or self-hosted on PostgreSQL/pgvector.
4
+
5
+ ## Canonical URLs
6
+
7
+ - Documentation & API reference: https://contextdb.ai/docs
8
+ - AI coding-agent integration guide: https://contextdb.ai/for-agents.txt
9
+ - Hosted OAuth 2.1 MCP guide: https://contextdb.ai/mcp
10
+ - Open-core boundary: https://contextdb.ai/open-core
11
+ - Source repository: https://github.com/atomsai/contextdb
12
+ - PyPI package (`pycontextdb==0.4.9`): https://pypi.org/project/pycontextdb/
13
+ - MCP plugin & Agent Skills: https://github.com/atomsai/contextdb-mcp-plugin
14
+ - Cloud clients (`contextdb-cloud-client`, `@contextdb/cloud`) & Memory CI: https://github.com/atomsai/contextdb-clients
15
+
16
+ ## Choose the right mode
17
+
18
+ - **Local / offline / self-hosted (`pycontextdb`):** Use when you want an embedded SQLite or self-hosted PostgreSQL engine in Python, or when "local only" / "no cloud" constraints apply.
19
+ - **Hosted multi-tenant API (`ContextDB Cloud`):** Use `contextdb-cloud-client` (Python) or `@contextdb/cloud` (TypeScript) against `https://api.contextdb.ai` from server-side code (`CONTEXTDB_API_KEY`).
20
+ - **OAuth 2.1 MCP connector (`https://api.contextdb.ai/mcp`):** Connect Cursor, Claude Code, Codex, VS Code, ChatGPT, or Grok with zero API keys; server binds one project and private partition.
21
+ - **When NOT to use:** If a user requires zero storage / zero retention for a turn, do not call `add` or `remember`. ContextDB does not replace your transactional system of record or enforce downstream authorization on its own.
22
+
23
+ ## Install
24
+
25
+ ```bash
26
+ pip install pycontextdb # SQLite + NumPy + hybrid BM25/vector RRF + trust model
27
+ pip install "pycontextdb[postgres]" # asyncpg + pgvector backend
28
+ pip install "pycontextdb[local]" # local SentenceTransformers embeddings
29
+ pip install "pycontextdb[serve]" # local HTTP + /mcp server (`contextdb serve`)
30
+ ```
31
+
32
+ ## Minimal Verified Example (`pycontextdb 0.4.9`)
33
+
34
+ ```python
35
+ import asyncio
36
+ import contextdb
37
+
38
+ async def main() -> None:
39
+ db = contextdb.init(
40
+ user_id="cust_42",
41
+ embedding_model="mock",
42
+ llm_model="mock",
43
+ llm_api_key="mock", # omit mock args to use configured real providers
44
+ pii_action="redact",
45
+ )
46
+ async with db:
47
+ await db.factual.add(
48
+ "Thursday afternoon appointment is confirmed.",
49
+ source="user_stated",
50
+ entity="appointment",
51
+ attribute="time",
52
+ action_relevant=True,
53
+ )
54
+ await db.factual.add(
55
+ "Caller mentioned Friday might also work.",
56
+ source="agent_inferred",
57
+ entity="appointment",
58
+ attribute="backup_time",
59
+ action_relevant=True,
60
+ )
61
+
62
+ # Grounding recall (hybrid BM25 + semantic + graph RRF; supports as_of=)
63
+ grounded = await db.factual.recall("When is the appointment?", top_k=5)
64
+
65
+ # Pre-action gate confined to a specific entity + attribute slot
66
+ trusted = await db.factual.recall_for_action(
67
+ "book appointment",
68
+ entity="appointment",
69
+ attribute="time",
70
+ )
71
+ pending = await db.factual.pending_confirmations(
72
+ entity="appointment",
73
+ attribute="backup_time",
74
+ )
75
+ print(len(grounded), len(trusted), len(pending)) # -> 2 1 1
76
+
77
+ asyncio.run(main())
78
+ ```
79
+
80
+ ## Framework Adapters (verified signatures)
81
+
82
+ ```python
83
+ from contextdb.integrations.langchain import ContextDBMemory
84
+ memory = ContextDBMemory(db, session_id="chat-1")
85
+
86
+ from contextdb.integrations.openai_tools import tool_schemas, make_tool_handlers
87
+ tools = tool_schemas()
88
+ handlers = make_tool_handlers(db)
89
+
90
+ from contextdb.integrations.crewai import ContextDBCrewMemory
91
+ crew_memory = ContextDBCrewMemory(db, top_k=5)
92
+ ```
93
+
94
+ ## Local HTTP & MCP Server
95
+
96
+ ```bash
97
+ pip install "pycontextdb[serve]"
98
+ contextdb serve --http --host 127.0.0.1 --port 8080 --token "$CONTEXTDB_SERVE_TOKEN"
99
+ ```
@@ -41,7 +41,7 @@ from contextdb.core.policy import TrustPolicy
41
41
  from contextdb.pool import ContextDBPool
42
42
  from contextdb.utils.embeddings import EmbeddingProvider
43
43
 
44
- __version__ = "0.4.7"
44
+ __version__ = "0.4.9"
45
45
 
46
46
  __all__ = [
47
47
  "Clock",