Embedded graph + vector + full-text database with Datalog — a maintained fork of CozoDB, tuned as a substrate for agentic memory.
Project description
mnestic (Python)
Embedded graph + vector + full-text database with Datalog queries — a maintained fork of CozoDB, tuned as a substrate for agentic memory. This package is the in-process Python binding (no server required).
mnestic is not the official CozoDB and is not affiliated with or endorsed by its original authors. All credit for the original design belongs to Ziyang Hu and the Cozo Project Authors. See the fork repository for provenance and licensing.
pip install mnestic
from mnestic import CozoDbPy
db = CozoDbPy("mem", "", "{}") # engines: "mem", "sqlite" (file path), "rocksdb" (dir path)
db.run_script("?[x] <- [[1],[2],[3]]", {}, False)
# One-call hybrid retrieval (HNSW + full-text fused with Reciprocal Rank Fusion),
# over a relation that has an HNSW index and an FTS index:
hits = db.hybrid_search({
"relation": "docs",
"vector_index": "vec", "query_vector": [0.1, 0.9], "vector_k": 5,
"fts_index": "fts", "query_text": "vector search", "fts_k": 5,
})
# -> {"headers": ["id", "score"], "rows": [["d3", 0.033], ...], "next": None}
# Pass "detailed": True for per-leg contributions — one row per (item, leg)
# with the within-leg rank the fusion used and the leg's raw score:
# headers ["id","score","list_id","leg_rank","leg_score"]
The "rocksdb" persistent backend now ships in the published wheel —
CozoDbPy("rocksdb", "./my.db", "{}") works straight from pip install mnestic.
The source distribution stays SQLite/compact-only, so the persistent engine is
wheel-only.
Upgrade note (0.10.6): a persistent database whose relation catalogs were
last written by a build older than 0.10.0 could fail to open with Cannot deserialize relation metadata from bytes after upgrading to 0.10.0–0.10.5.
0.10.6 fixes this — legacy catalogs open again with no migration, so upgrade to
0.10.6 if you carry a pre-0.10.0 database.
run_script takes an optional timeout= — a per-query wall-clock budget in
seconds; on expiry the query raises an eval::timeout error.
db.set_default_query_timeout(secs) sets a Db-wide default and
db.default_query_timeout() reads it back; the effective budget for a query is
the minimum of that default and any per-call timeout.
New in 0.13.0
0.13.0 is a combined correctness-and-capability release. The Python-facing highlights:
-
The published wheel now honours RocksDB table options. A block cache, block size, and index/filter caching configured through an
optionsfile were silently discarded on every open, soCozoDbPy("rocksdb", ...)ran with an 8 MB default cache and 4 KB blocks no matter what the file asked for. Any read-path benchmark taken against a RocksDB store before this release measured a slower engine than mnestic actually is. Fixed in the bundledmnestic-rocks0.1.10; the SQLite-only source distribution was never affected. -
Datetime standard library (
dt_*), reachable fromrun_script. Component extractors (dt_year…dt_dow),dt_trunc, calendar-awaredt_add/dt_diff, strftimedt_format, anddt_to_validity— the typed bridge from float Unix seconds to aValidity's integer microseconds.@and:as_ofnow accept aValidity-typed expression (@ dt_to_validity(parse_timestamp('2024-01-01'))), which together with 0.12.2's float rejection closes the seconds-vs-microseconds trap that is especially easy to hit from Python. The newdt_*names are reserved againstregister_custom_aggr. -
Better parse errors. A failed
run_scriptnow points its caret at the deepest position the parser reached and adds ahelp:line naming the literal tokens that would have been accepted (expected one of: :=, <-, <~) — the improved text flows straight through the wheel. Index-search diagnostics now name the index kind that actually failed (fts_query_required, not the oldhnsw_query_required). -
hybrid_search: budgeted graph expansion and optional legs. Agraph_legsentry gains optional keys (max_nodes,max_cost,weight_col,graph,seed_from_legs,gate_relation/gate_cols/admit); settingmax_nodesruns the leg as cheapest-first weighted expansion under a distinct-node budget.vector_indexandfts_indexare now optional, so you can fuse any non-empty subset of {vector, FTS, graph} legs. Existing dicts parse unchanged, but an unknown key in agraph_legsentry is now rejected loudly, so a typo likemax_hopcan no longer silently run the leg with defaults. -
The
!=factorized-count rewrite is restored, default OFF. Enable the Db-wide switch withdb.set_query_factorization(True)(read it back withdb.query_factorization()); it rewrites an eligiblecount()-over-join carrying an inequality via inclusion–exclusion, sound behind a stored-column type gate. Measured ~140× on LSQB q6. It stays off by default until a nightly soak clears the default-on flip. -
Corrupt data raises instead of crashing the interpreter. A corrupt value blob in a stored relation used to raise
PanicException— aBaseExceptionsubclass thatexcept Exception:does not catch. It is now an ordinaryeval::corrupt_value_blobquery error naming the key: run::repair_corrupt <relation>to drop the unreadable rows, then::reindex <relation>if that relation carries an HNSW/FTS/LSH index. HNSW indexes built by any release through 0.12.2 can also carry stale nodes/edges from null-vector and pre-existing-row bugs — rebuild once per affected relation with::reindex <relation>. Your rows are untouched;::reindexrebuilds index relations only.
See the fork changelog
for the full per-case upgrade guidance — pre-1970 timestamps, restore_backup
relation-id reconciliation, and the hybrid-leg ranking changes (fusion legs now
require distinct labels, and a graph leg no longer re-scores its own seeds).
For idiomatic LangChain / LlamaIndex usage, install the integration packages
(langchain-mnestic, llama-index-vector-stores-mnestic).
The query language (CozoScript / Datalog) and engine semantics follow CozoDB; see the upstream documentation and the fork changelog.
License
Mozilla Public License 2.0. Original work © 2022 The Cozo Project Authors; fork modifications © 2026 Shan Rizvi.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mnestic-0.13.0.tar.gz.
File metadata
- Download URL: mnestic-0.13.0.tar.gz
- Upload date:
- Size: 708.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba5c25e32ca8d482182e3d45300339da17843c6900bdfba5dc0ca5826e6c1986
|
|
| MD5 |
280a6f5de54aa8a99aed5e1e9cc6f663
|
|
| BLAKE2b-256 |
95a57168d47f9dc83033d9be6a14ba307b54da58e72d83e3867d645fa324d514
|
Provenance
The following attestation bundles were made for mnestic-0.13.0.tar.gz:
Publisher:
python-publish.yml on shuruheel/mnestic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mnestic-0.13.0.tar.gz -
Subject digest:
ba5c25e32ca8d482182e3d45300339da17843c6900bdfba5dc0ca5826e6c1986 - Sigstore transparency entry: 2194843260
- Sigstore integration time:
-
Permalink:
shuruheel/mnestic@aecfd1fcf4aecf09675ebba5d78fc61f6c69da6d -
Branch / Tag:
refs/tags/py-v0.13.0 - Owner: https://github.com/shuruheel
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@aecfd1fcf4aecf09675ebba5d78fc61f6c69da6d -
Trigger Event:
push
-
Statement type:
File details
Details for the file mnestic-0.13.0-cp37-abi3-win_amd64.whl.
File metadata
- Download URL: mnestic-0.13.0-cp37-abi3-win_amd64.whl
- Upload date:
- Size: 10.7 MB
- Tags: CPython 3.7+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
223aec0c51f50aab459f3ef4ce662b9a692b5ebf38bef64024684b76558e550b
|
|
| MD5 |
a54df321a02b474bea785bfc72c4afaf
|
|
| BLAKE2b-256 |
2a3b372fe34c07bce18542c2f0e0a02702333405c4d99595ae424966e5fa465e
|
Provenance
The following attestation bundles were made for mnestic-0.13.0-cp37-abi3-win_amd64.whl:
Publisher:
python-publish.yml on shuruheel/mnestic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mnestic-0.13.0-cp37-abi3-win_amd64.whl -
Subject digest:
223aec0c51f50aab459f3ef4ce662b9a692b5ebf38bef64024684b76558e550b - Sigstore transparency entry: 2194843295
- Sigstore integration time:
-
Permalink:
shuruheel/mnestic@aecfd1fcf4aecf09675ebba5d78fc61f6c69da6d -
Branch / Tag:
refs/tags/py-v0.13.0 - Owner: https://github.com/shuruheel
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@aecfd1fcf4aecf09675ebba5d78fc61f6c69da6d -
Trigger Event:
push
-
Statement type:
File details
Details for the file mnestic-0.13.0-cp37-abi3-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: mnestic-0.13.0-cp37-abi3-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 13.4 MB
- Tags: CPython 3.7+, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
320fa2ac49474db601923f811c2be24a5abaeb8ddda99da254b76146ff6dee02
|
|
| MD5 |
2f06e235385bf94d0fe9f45fb687d5fd
|
|
| BLAKE2b-256 |
78590763398266c686724b1826ded0f3378c9a6dfa930677503667828b1b532b
|
Provenance
The following attestation bundles were made for mnestic-0.13.0-cp37-abi3-manylinux_2_28_x86_64.whl:
Publisher:
python-publish.yml on shuruheel/mnestic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mnestic-0.13.0-cp37-abi3-manylinux_2_28_x86_64.whl -
Subject digest:
320fa2ac49474db601923f811c2be24a5abaeb8ddda99da254b76146ff6dee02 - Sigstore transparency entry: 2194843284
- Sigstore integration time:
-
Permalink:
shuruheel/mnestic@aecfd1fcf4aecf09675ebba5d78fc61f6c69da6d -
Branch / Tag:
refs/tags/py-v0.13.0 - Owner: https://github.com/shuruheel
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@aecfd1fcf4aecf09675ebba5d78fc61f6c69da6d -
Trigger Event:
push
-
Statement type:
File details
Details for the file mnestic-0.13.0-cp37-abi3-manylinux_2_28_aarch64.whl.
File metadata
- Download URL: mnestic-0.13.0-cp37-abi3-manylinux_2_28_aarch64.whl
- Upload date:
- Size: 13.2 MB
- Tags: CPython 3.7+, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a83e963d405801182b021813e5d1a64ffbf4dd99ef7ef0cade5cf10a79b2052
|
|
| MD5 |
36f44f636d3b09bc6fee5133cfd6a866
|
|
| BLAKE2b-256 |
22378b8d398f879dbf377ece45dd95c6f071bcc22357933cf9afcd12c776247d
|
Provenance
The following attestation bundles were made for mnestic-0.13.0-cp37-abi3-manylinux_2_28_aarch64.whl:
Publisher:
python-publish.yml on shuruheel/mnestic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mnestic-0.13.0-cp37-abi3-manylinux_2_28_aarch64.whl -
Subject digest:
8a83e963d405801182b021813e5d1a64ffbf4dd99ef7ef0cade5cf10a79b2052 - Sigstore transparency entry: 2194843314
- Sigstore integration time:
-
Permalink:
shuruheel/mnestic@aecfd1fcf4aecf09675ebba5d78fc61f6c69da6d -
Branch / Tag:
refs/tags/py-v0.13.0 - Owner: https://github.com/shuruheel
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@aecfd1fcf4aecf09675ebba5d78fc61f6c69da6d -
Trigger Event:
push
-
Statement type:
File details
Details for the file mnestic-0.13.0-cp37-abi3-macosx_11_0_x86_64.whl.
File metadata
- Download URL: mnestic-0.13.0-cp37-abi3-macosx_11_0_x86_64.whl
- Upload date:
- Size: 11.8 MB
- Tags: CPython 3.7+, macOS 11.0+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74b68053169f7f247aa756643ea8a1273ad1b69b4ce45d992411d333ccc4d6c0
|
|
| MD5 |
99c6aa6b924e1d8023da605808c9182d
|
|
| BLAKE2b-256 |
e2dd81fe5c84cc9921fe787a820026e06f0d0309bbfff36925b716880de7eac6
|
Provenance
The following attestation bundles were made for mnestic-0.13.0-cp37-abi3-macosx_11_0_x86_64.whl:
Publisher:
python-publish.yml on shuruheel/mnestic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mnestic-0.13.0-cp37-abi3-macosx_11_0_x86_64.whl -
Subject digest:
74b68053169f7f247aa756643ea8a1273ad1b69b4ce45d992411d333ccc4d6c0 - Sigstore transparency entry: 2194843305
- Sigstore integration time:
-
Permalink:
shuruheel/mnestic@aecfd1fcf4aecf09675ebba5d78fc61f6c69da6d -
Branch / Tag:
refs/tags/py-v0.13.0 - Owner: https://github.com/shuruheel
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@aecfd1fcf4aecf09675ebba5d78fc61f6c69da6d -
Trigger Event:
push
-
Statement type:
File details
Details for the file mnestic-0.13.0-cp37-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: mnestic-0.13.0-cp37-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 10.6 MB
- Tags: CPython 3.7+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2715d6362b101312f93027ba7c649dd9f26887ac077f1629e369f286b4279a65
|
|
| MD5 |
c93bc734f90888ee61fdf1a8d21e922c
|
|
| BLAKE2b-256 |
06d2c3da9bd5a995994598682715313257745cc2f9eee38e9fc20b3a66da9497
|
Provenance
The following attestation bundles were made for mnestic-0.13.0-cp37-abi3-macosx_11_0_arm64.whl:
Publisher:
python-publish.yml on shuruheel/mnestic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mnestic-0.13.0-cp37-abi3-macosx_11_0_arm64.whl -
Subject digest:
2715d6362b101312f93027ba7c649dd9f26887ac077f1629e369f286b4279a65 - Sigstore transparency entry: 2194843271
- Sigstore integration time:
-
Permalink:
shuruheel/mnestic@aecfd1fcf4aecf09675ebba5d78fc61f6c69da6d -
Branch / Tag:
refs/tags/py-v0.13.0 - Owner: https://github.com/shuruheel
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@aecfd1fcf4aecf09675ebba5d78fc61f6c69da6d -
Trigger Event:
push
-
Statement type: