coalent 0.2.0__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 (56) hide show
  1. coalent-0.2.0/.gitignore +36 -0
  2. coalent-0.2.0/CHANGELOG.md +45 -0
  3. coalent-0.2.0/LICENSE +201 -0
  4. coalent-0.2.0/PKG-INFO +248 -0
  5. coalent-0.2.0/README.md +204 -0
  6. coalent-0.2.0/brand/BRAND.md +54 -0
  7. coalent-0.2.0/brand/favicon.svg +15 -0
  8. coalent-0.2.0/brand/logomark.svg +18 -0
  9. coalent-0.2.0/brand/tokens.css +25 -0
  10. coalent-0.2.0/brand/tokens.json +23 -0
  11. coalent-0.2.0/brand/wordmark-dark.svg +19 -0
  12. coalent-0.2.0/brand/wordmark.png +0 -0
  13. coalent-0.2.0/brand/wordmark.svg +21 -0
  14. coalent-0.2.0/examples/eval_demo.py +21 -0
  15. coalent-0.2.0/examples/quickstart.py +42 -0
  16. coalent-0.2.0/examples/rag_integration.py +65 -0
  17. coalent-0.2.0/pyproject.toml +62 -0
  18. coalent-0.2.0/src/coalent/__init__.py +122 -0
  19. coalent-0.2.0/src/coalent/adapters/__init__.py +1 -0
  20. coalent-0.2.0/src/coalent/adapters/providers.py +91 -0
  21. coalent-0.2.0/src/coalent/cli.py +206 -0
  22. coalent-0.2.0/src/coalent/domain/__init__.py +1 -0
  23. coalent-0.2.0/src/coalent/domain/models.py +121 -0
  24. coalent-0.2.0/src/coalent/evaluation/__init__.py +6 -0
  25. coalent-0.2.0/src/coalent/evaluation/harness.py +165 -0
  26. coalent-0.2.0/src/coalent/events/__init__.py +33 -0
  27. coalent-0.2.0/src/coalent/events/connectors.py +128 -0
  28. coalent-0.2.0/src/coalent/events/dispatcher.py +60 -0
  29. coalent-0.2.0/src/coalent/events/http.py +35 -0
  30. coalent-0.2.0/src/coalent/events/signatures.py +19 -0
  31. coalent-0.2.0/src/coalent/integrations.py +72 -0
  32. coalent-0.2.0/src/coalent/py.typed +0 -0
  33. coalent-0.2.0/src/coalent/semantic/__init__.py +65 -0
  34. coalent-0.2.0/src/coalent/semantic/cache.py +503 -0
  35. coalent-0.2.0/src/coalent/semantic/embedding.py +68 -0
  36. coalent-0.2.0/src/coalent/semantic/memory.py +149 -0
  37. coalent-0.2.0/src/coalent/semantic/ports.py +61 -0
  38. coalent-0.2.0/src/coalent/semantic/serde.py +111 -0
  39. coalent-0.2.0/src/coalent/semantic/store.py +199 -0
  40. coalent-0.2.0/src/coalent/semantic/synthesizer.py +192 -0
  41. coalent-0.2.0/src/coalent/semantic/unit.py +46 -0
  42. coalent-0.2.0/src/coalent/semantic/vector.py +202 -0
  43. coalent-0.2.0/tests/test_cli.py +68 -0
  44. coalent-0.2.0/tests/test_composite_retriever.py +85 -0
  45. coalent-0.2.0/tests/test_context.py +97 -0
  46. coalent-0.2.0/tests/test_evaluation.py +40 -0
  47. coalent-0.2.0/tests/test_freshness.py +90 -0
  48. coalent-0.2.0/tests/test_integrations.py +36 -0
  49. coalent-0.2.0/tests/test_json_synthesizer.py +84 -0
  50. coalent-0.2.0/tests/test_persistence.py +76 -0
  51. coalent-0.2.0/tests/test_redis_store.py +163 -0
  52. coalent-0.2.0/tests/test_relationships.py +84 -0
  53. coalent-0.2.0/tests/test_retrievers.py +36 -0
  54. coalent-0.2.0/tests/test_semantic_core.py +83 -0
  55. coalent-0.2.0/tests/test_synthesizer.py +124 -0
  56. coalent-0.2.0/tests/test_vector_adapters.py +75 -0
@@ -0,0 +1,36 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ .eggs/
6
+ build/
7
+ dist/
8
+ .venv/
9
+ venv/
10
+ env/
11
+
12
+ # Tooling
13
+ .pytest_cache/
14
+ .mypy_cache/
15
+ .ruff_cache/
16
+ .coverage
17
+ htmlcov/
18
+
19
+ # IDE / OS
20
+ .vscode/
21
+ .idea/
22
+ .DS_Store
23
+ Thumbs.db
24
+
25
+ # Internal — NOT for publication (audits, planning, design, commercial strategy).
26
+ # NOTE: this only keeps them out of a *fresh* repo. The existing repo's history
27
+ # already contains them — publish from a clean repo (see RELEASING notes).
28
+ /ARCHITECTURE_REVIEW.md
29
+ /REMEDIATION_PLAN.md
30
+ /INTELLIGENCE_CORE_CONTRACT.md
31
+ /PHASE1_PLAN.md
32
+ /OPEN_CORE.md
33
+ /cognitive-cache-design.html
34
+ # Review before publishing — likely internal:
35
+ /RELEASING.md
36
+ /brand/showcase.html
@@ -0,0 +1,45 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. This project adheres to
4
+ [Semantic Versioning](https://semver.org/).
5
+
6
+ ## [0.2.0]
7
+
8
+ First public release — a real-time, provenance-invalidated cognitive cache for AI
9
+ agents and RAG. Framework-neutral, pluggable, and fully typed.
10
+
11
+ ### Added
12
+ - **SemanticCache** — a `get(query)` read path: an embedding-keyed cache of
13
+ decision-ready understanding that retains the raw evidence with every unit, so it
14
+ can never return less than plain retrieval.
15
+ - **Provenance invalidation** — each unit records the exact sources it used;
16
+ `source_changed` / `source_deleted` dirty only the units that used them and skip
17
+ no-op changes via a content-hash compare. Units re-materialize lazily on read.
18
+ - **Retrievers** — `InMemoryRetriever`, `FunctionRetriever`, `CompositeRetriever`, a
19
+ `BaseVectorRetriever`, and shipped bring-your-own-client adapters for Qdrant,
20
+ Chroma, and pgvector (with pass-through search).
21
+ - **Synthesizers** — `LLMSynthesizer` (structured, citation-grounded understanding;
22
+ user-owned instruction + fields) and `JSONPassthroughSynthesizer` (cache already
23
+ structured tool/API JSON with no LLM call). Providers for OpenAI, Anthropic, and a
24
+ deterministic stub.
25
+ - **Context intelligence** — coverage gate with auto-escalation, minimum-context
26
+ projection, context strategies, and lazy cross-unit relationships.
27
+ - **Freshness** — `FreshnessPolicy` (TTL + revalidate-by-hash) for feed-less
28
+ API/tool sources.
29
+ - **Persistence** — durable, restart-safe stores: `InMemoryCognitionStore`,
30
+ `SQLiteCognitionStore` (stdlib, no server), and `RedisCognitionStore`. The
31
+ invalidation graph rebuilds on startup.
32
+ - **Events** — GitHub / deploy / Jira / generic-CDC connectors with HMAC signature
33
+ verification and an event dispatcher.
34
+ - **Integrations** — a graph-node helper (`make_cognition_node`) and MCP tool specs
35
+ (`build_mcp_tools`) over the one-call read API.
36
+ - **CLI** — `coalent` inspects and manages a persistent cache (ls / show / dirty /
37
+ invalidate / evict / purge / stats).
38
+ - **Eval harness** — measures accuracy, stale-rate, and token cost against naive RAG
39
+ and a no-invalidation cache.
40
+
41
+ ### Notes
42
+ - The core installs with **zero required dependencies**. Optional extras add LLM
43
+ providers (`openai`, `anthropic`), vector adapters (`qdrant`, `chroma`,
44
+ `pgvector`), the distributed store (`redis`), and a webhook server (`server`).
45
+ - Alpha: the public API may change before 1.0.
coalent-0.2.0/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative
95
+ Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and do
117
+ not modify the License. You may add Your own attribution notices
118
+ within Derivative Works that You distribute, alongside or as an
119
+ addendum to the NOTICE text from the Work, provided that such
120
+ additional attribution notices cannot be construed as modifying
121
+ the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Nisarg Pujara
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
coalent-0.2.0/PKG-INFO ADDED
@@ -0,0 +1,248 @@
1
+ Metadata-Version: 2.4
2
+ Name: coalent
3
+ Version: 0.2.0
4
+ Summary: A real-time, provenance-invalidated cognitive cache layer for AI agents and RAG.
5
+ Project-URL: Homepage, https://github.com/Vectorlink-Labs/coalent
6
+ Project-URL: Repository, https://github.com/Vectorlink-Labs/coalent
7
+ Project-URL: Documentation, https://github.com/Vectorlink-Labs/coalent#readme
8
+ Project-URL: Issues, https://github.com/Vectorlink-Labs/coalent/issues
9
+ Author-email: Nisarg Pujara <nisarg.pujara@vectorlinklabs.com>
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ Keywords: agents,cache,context,context-engineering,crewai,langgraph,llm,mcp,provenance,rag
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Software Development :: Libraries
19
+ Requires-Python: >=3.10
20
+ Provides-Extra: anthropic
21
+ Requires-Dist: anthropic>=0.40; extra == 'anthropic'
22
+ Provides-Extra: chroma
23
+ Requires-Dist: chromadb>=0.4; extra == 'chroma'
24
+ Provides-Extra: dev
25
+ Requires-Dist: mypy>=1.8; extra == 'dev'
26
+ Requires-Dist: pytest-cov; extra == 'dev'
27
+ Requires-Dist: pytest>=7.0; extra == 'dev'
28
+ Requires-Dist: ruff>=0.4; extra == 'dev'
29
+ Provides-Extra: langgraph
30
+ Requires-Dist: langgraph>=0.2; extra == 'langgraph'
31
+ Provides-Extra: mcp
32
+ Requires-Dist: mcp>=1.0; extra == 'mcp'
33
+ Provides-Extra: openai
34
+ Requires-Dist: openai>=1.0; extra == 'openai'
35
+ Provides-Extra: pgvector
36
+ Requires-Dist: psycopg[binary]>=3.1; extra == 'pgvector'
37
+ Provides-Extra: qdrant
38
+ Requires-Dist: qdrant-client>=1.7; extra == 'qdrant'
39
+ Provides-Extra: redis
40
+ Requires-Dist: redis>=5.0; extra == 'redis'
41
+ Provides-Extra: server
42
+ Requires-Dist: fastapi>=0.110; extra == 'server'
43
+ Description-Content-Type: text/markdown
44
+
45
+ <p align="center">
46
+ <img src="https://raw.githubusercontent.com/Vectorlink-Labs/coalent/main/brand/wordmark.png" alt="Coalent" width="320">
47
+ </p>
48
+
49
+ <p align="center">
50
+ <b>Real-time, provenance-invalidated context for AI agents &amp; RAG.</b><br>
51
+ <i>Build understanding once. Reuse it everywhere. Keep it fresh — automatically.</i>
52
+ </p>
53
+
54
+ <p align="center">
55
+ <img alt="pypi" src="https://img.shields.io/pypi/v/coalent?color=5145E5">
56
+ <img alt="python" src="https://img.shields.io/badge/python-3.10%2B-4F46E5">
57
+ <img alt="license" src="https://img.shields.io/badge/license-Apache%202.0-22D3EE">
58
+ <img alt="typed" src="https://img.shields.io/badge/mypy-strict-2DD4BF">
59
+ <img alt="tests" src="https://img.shields.io/badge/tests-passing-10B981">
60
+ </p>
61
+
62
+ <p align="center">
63
+ <b>📖 <a href="https://coalent.ai/docs">Documentation</a></b> &nbsp;·&nbsp; <a href="https://coalent.ai">coalent.ai</a>
64
+ </p>
65
+
66
+ <p align="center">
67
+ <a href="#quickstart">Quickstart</a> ·
68
+ <a href="#how-it-works">How it works</a> ·
69
+ <a href="#bring-your-own-stack">Bring your own stack</a> ·
70
+ <a href="#benchmark">Benchmark</a> ·
71
+ <a href="#cli">CLI</a>
72
+ </p>
73
+
74
+ ---
75
+
76
+ > **Your agent re-reads the same sources on every call — and the moment a source changes, every cached answer is silently wrong.**
77
+ >
78
+ > Coalent builds the *understanding* once, caches it by what the query **means**, and invalidates it **surgically** the instant an underlying source changes. As correct as re-reading everything, at a fraction of the cost — and never stale.
79
+
80
+ ## Why Coalent
81
+
82
+ Every context layer is forced to trade off three things. Coalent is built to hold all three at once:
83
+
84
+ - 🧠 **Understanding, not chunks.** It caches the decision-ready understanding your LLM produced — *and retains the raw evidence with every unit*, so it can never return less than plain retrieval.
85
+ - ♻️ **Reuse across queries and agents.** A semantic cache keyed by query *meaning*: ask again, or from another agent, and it's a warm hit — no re-retrieval, no re-synthesis.
86
+ - 🌿 **Fresh by provenance.** Every unit remembers the exact sources it used. When one changes, only the units that actually used it go stale — precisely, automatically, and lazily.
87
+
88
+ Coalent sits **above retrieval** — bring any retriever (vector DB, hybrid search, GraphRAG, tools, APIs). It's the freshness-and-reuse layer, not another retriever.
89
+
90
+ ## Install
91
+
92
+ ```bash
93
+ pip install coalent # the core has zero required dependencies
94
+ ```
95
+
96
+ ## Quickstart
97
+
98
+ Runs as-is — `StubSynthesizer` needs no API key, so you can feel the loop in ten seconds:
99
+
100
+ ```python
101
+ from coalent import SemanticCache, InMemoryRetriever, StubSynthesizer
102
+
103
+ # 1. Any retriever — a vector DB, a tool, an API. (In-memory here for the demo.)
104
+ retriever = InMemoryRetriever()
105
+ retriever.add("confluence:hr", "Leave policy: 21 days of annual leave per year.")
106
+
107
+ # 2. Build the cache. Swap StubSynthesizer for a real LLM below.
108
+ cache = SemanticCache(retriever, StubSynthesizer())
109
+
110
+ # 3. Ask. The first call builds understanding and caches it; the next is a warm hit.
111
+ result = cache.get("what is our leave policy?")
112
+ print(result.context["understanding"])
113
+ print(result.cache_hit) # False (cold) -> True on the next call
114
+
115
+ # 4. A source changed? Only the units that used it go stale — surgically.
116
+ cache.source_changed("confluence:hr", text="Leave policy: now 25 days.")
117
+ # the next matching read rebuilds just that one unit, lazily
118
+ ```
119
+
120
+ Wire in a real model — any text-in / text-out LLM works:
121
+
122
+ ```python
123
+ from coalent import SemanticCache, LLMSynthesizer, OpenAIProvider
124
+
125
+ cache = SemanticCache(retriever, LLMSynthesizer(OpenAIProvider(), model="gpt-4o-mini"))
126
+ ```
127
+
128
+ ## How it works
129
+
130
+ ```
131
+ query ──► embed ──► semantic cache
132
+ │ hit & fresh? ──► serve cached understanding (no retrieval, no LLM)
133
+ │ miss / stale? ─┐
134
+ ▼ ▼
135
+ your Retriever ──► your Synthesizer ──► Cognition unit
136
+ (vector/tool/API) (LLM or passthrough) { understanding
137
+ ▲ + raw evidence
138
+ │ + provenance }
139
+ source changed ────────────┘ dirties ONLY the units that used that source
140
+ ```
141
+
142
+ 1. **Embed the query** and look for an existing unit with similar meaning.
143
+ 2. **Hit + fresh** → return the cached understanding (no retrieval, no LLM call).
144
+ 3. **Miss or stale** → retrieve, synthesize understanding, **retain the raw evidence**, record **provenance** (the exact sources used), and cache it.
145
+ 4. **A source changes** → `source_changed(id)` marks only the units whose provenance includes that id; they rebuild lazily on the next read.
146
+
147
+ Unchanged content is skipped via a content-hash compare, so a no-op change costs nothing.
148
+
149
+ ## Bring your own stack
150
+
151
+ Coalent owns a tiny contract and passes everything else through to your tools.
152
+
153
+ **Retrievers** — a ladder from one-liner to full control:
154
+
155
+ | You have… | Use |
156
+ |---|---|
157
+ | Qdrant / Chroma / pgvector | a shipped adapter (bring-your-own-client) |
158
+ | another vector DB | extend `BaseVectorRetriever` |
159
+ | an existing search function | `FunctionRetriever` |
160
+ | several sources to fuse | `CompositeRetriever` |
161
+ | anything else | implement `Retriever` (one method) |
162
+
163
+ ```python
164
+ from coalent import QdrantRetriever
165
+
166
+ retriever = QdrantRetriever(client=my_client, collection="docs", embed=my_embed)
167
+ ```
168
+
169
+ **Synthesizers** — turn evidence into understanding:
170
+
171
+ - `LLMSynthesizer` — structured, citation-grounded understanding via your LLM (OpenAI, Anthropic, or any provider). You own the `instruction` and `fields`; Coalent owns the source / strict-JSON / citation envelope, so provenance is captured no matter what you ask for.
172
+ - `JSONPassthroughSynthesizer` — for already-structured tool/API JSON: caches it *as* the understanding, **no LLM call**.
173
+
174
+ **Stores** — durable and restart-safe (the invalidation graph rebuilds on startup):
175
+
176
+ ```python
177
+ from coalent import SemanticCache, SQLiteCognitionStore # stdlib, no server
178
+ from coalent import RedisCognitionStore # shared across processes / hosts
179
+
180
+ cache = SemanticCache(retriever, synthesizer, store=SQLiteCognitionStore("coalent.db"))
181
+ ```
182
+
183
+ **Any agent framework** — the read API is a single call, so it drops in anywhere. Shipped helpers for graph nodes and MCP tools:
184
+
185
+ ```python
186
+ from coalent import make_cognition_node, build_mcp_tools
187
+
188
+ node = make_cognition_node(cache) # a graph node: state -> { context: fresh understanding }
189
+ tools = build_mcp_tools(cache) # expose the cache as an MCP tool
190
+ ```
191
+
192
+ ## Benchmark
193
+
194
+ A real-LLM, quality-first benchmark (gpt-4o-mini, graded by an independent gpt-4o judge) on number-dense documents — answering from Coalent's *understanding* vs the full raw context, with a source change midway:
195
+
196
+ | System | Accuracy | Stays fresh | Context tokens / read |
197
+ |---|:---:|:---:|:---:|
198
+ | Full-context RAG | 100% | ✓ | 283 |
199
+ | Normal cache (raw chunks) | 86% | ✗ stale | 283 |
200
+ | **Coalent** | **100%** | **✓** | **96** |
201
+
202
+ Coalent **matches full-context RAG accuracy** (independently graded), **never goes stale** after a source change (a normal cache does), and sends **~66% fewer context tokens — up to 75% on large documents.** Cost optimization without trading away quality. *(gpt-4o corroborates within ~3%; full two-model breakdown in the [docs](https://coalent.ai/docs/benchmark).)*
203
+
204
+ ## CLI
205
+
206
+ Installing Coalent gives you a `coalent` command — a `redis-cli` for your cognition cache (over a SQLite store):
207
+
208
+ ```console
209
+ $ coalent ls
210
+ STATUS HITS AGE SRC ID QUERY
211
+ fresh 6 2m 2 cog:c95a9d2897e0af what is our leave policy?
212
+ dirty 1 12m 1 cog:7f1a0b9c3d2e4f remote work rules
213
+
214
+ $ coalent show cog:c95a9d2897e0af # understanding + provenance + raw evidence
215
+ $ coalent invalidate confluence:98231 # fire a change event
216
+ $ coalent stats
217
+ ```
218
+
219
+ ## Documentation
220
+
221
+ 📚 **Full docs: [coalent.ai/docs](https://coalent.ai/docs)** — concepts, provenance & freshness, retrievers, synthesizers, persistence, worked examples (vector search, MCP & tools, agents), and the complete `get()` / data-model reference.
222
+
223
+ ## Install options
224
+
225
+ ```bash
226
+ pip install coalent # core, zero required deps
227
+ pip install "coalent[openai]" # OpenAI provider (also: anthropic)
228
+ pip install "coalent[qdrant]" # vector adapters (also: chroma, pgvector)
229
+ pip install "coalent[redis]" # distributed store
230
+ pip install "coalent[dev]" # tests + lint + types
231
+ ```
232
+
233
+ ## Contributing
234
+
235
+ Issues and PRs welcome. Run the gate before pushing:
236
+
237
+ ```bash
238
+ pip install -e ".[dev]"
239
+ pytest && ruff check src && mypy src
240
+ ```
241
+
242
+ ## Status &amp; license
243
+
244
+ **Alpha** — the API may change before 1.0. Fully typed (`mypy --strict`), linted, and tested.
245
+
246
+ Licensed under [Apache-2.0](./LICENSE).
247
+
248
+ <p align="center"><sub>Context that's trustworthy, not just cheap.</sub></p>