citadeldb-haystack
A Haystack DocumentStore backed by
Citadel. Encrypted at rest, embedded in your process, and deletes
that destroy the key, not just the row.
pip install citadeldb-haystack sentence-transformers
Requires citadeldb>=2.2,<3 and haystack-ai>=2.9,<4. Set CITADEL_KEY before
running the example. The embedding model downloads on first use and runs locally.
from haystack import Document
from haystack.components.embedders import SentenceTransformersTextEmbedder
from haystack.utils import Secret
from citadeldb_haystack import CitadelDocumentStore
embedder = SentenceTransformersTextEmbedder(model="sentence-transformers/all-mpnet-base-v2")
store = CitadelDocumentStore(
"corpus.cdl",
Secret.from_env_var("CITADEL_KEY"),
embedder=embedder,
dim=768,
embedding_similarity_function="cosine",
)
store.write_documents([
Document(id="d1", content="The deployment failed because the disk was full.",
meta={"chapter": "intro"}),
])
store.filter_documents({"field": "meta.chapter", "operator": "==", "value": "intro"})
dim defaults to 768 and must match your embedding model.
embedding_similarity_function is "cosine" or "dot_product" and is persisted
with the store. It defaults to Haystack's "dot_product"; choose "cosine"
explicitly when that is what produced the supplied vectors.
Embedders exposing model_id, model, or model_name record that identity automatically,
in that order. For a custom component without any of those attributes, pass a stable
model_id= explicitly; Citadel refuses to guess from the Python class name.
Pipeline serialization
Use a Haystack environment-variable Secret for pipeline serialization. Literal
passphrases cannot be serialized:
CitadelDocumentStore(
"literal.cdl", "literal-passphrase", embedder=embedder, dim=768
).to_dict()
# ValueError: Cannot serialize token-based secret.
CitadelDocumentStore(
"corpus.cdl", Secret.from_env_var("CITADEL_KEY"), embedder=embedder, dim=768,
embedding_similarity_function="cosine",
).to_dict()
# {... "key": {"type": "env_var", "env_vars": ["CITADEL_KEY"], ...}}
Use Secret.from_env_var for any store that goes into a saved pipeline.
Deletes destroy the key
Every document is sealed under its own key. Deleting destroys that key and removes the row. Pre-erasure backups or snapshots containing keys, and exported plaintext, are outside that erasure.
store.delete_documents(["d1"])
store.delete_all() # returns the number erased
DuplicatePolicy.NONE is treated as FAIL: duplicate ids are rejected.
Retrieval
embedder.warm_up()
query_embedding = embedder.run(text="Why did the release break?")["embedding"]
store.embedding_retrieval(
query_embedding,
top_k=5,
filters={"field": "meta.chapter", "operator": "==", "value": "intro"},
scale_score=False,
return_embedding=False,
)
Filters use Haystack's evaluator.
Top-level AND string equalities, including nested paths such as meta.person.name,
are passed to Citadel as payload filters. Other predicates filter ranked candidates; the
search window expands until top_k matches survive or the region is exhausted.
Notes
The store requires a Haystack text embedder. Documents that arrive without a vector are embedded with it, while vectors already supplied by the pipeline are stored as-is. Pass the same model to the pipeline and store so both paths remain in one vector space. The store warms the embedder lazily before its first model call and includes its configuration in pipeline serialization.
Citadel is embedded and one process owns the file. A path already open on this thread, under the same passphrase, is shared, so this can sit on the same database as another Citadel adapter; construct them on the same thread.
License
Apache-2.0
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
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 citadeldb_haystack-2.4.0.tar.gz.
File metadata
- Download URL: citadeldb_haystack-2.4.0.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65a8b89ff0ce00e190fcaa4cfd7a0e9a7bd22f8df8e5c1a36bc45fe45be4fb57
|
|
| MD5 |
38e6b339b7e3d88b7e14e3240a677bb6
|
|
| BLAKE2b-256 |
51ba1686dbd7c10272a8d2785e7a8f567f74121c07b0bdd068478d925574cd4e
|
Provenance
The following attestation bundles were made for citadeldb_haystack-2.4.0.tar.gz:
Publisher:
release-haystack.yml on yp3y5akh0v/citadel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
citadeldb_haystack-2.4.0.tar.gz -
Subject digest:
65a8b89ff0ce00e190fcaa4cfd7a0e9a7bd22f8df8e5c1a36bc45fe45be4fb57 - Sigstore transparency entry: 2799973288
- Sigstore integration time:
-
Permalink:
yp3y5akh0v/citadel@278e8c8b00632927ad18c66a5bc52218a5f53761 -
Branch / Tag:
refs/tags/v2.4.0 - Owner: https://github.com/yp3y5akh0v
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-haystack.yml@278e8c8b00632927ad18c66a5bc52218a5f53761 -
Trigger Event:
push
-
Statement type:
File details
Details for the file citadeldb_haystack-2.4.0-py3-none-any.whl.
File metadata
- Download URL: citadeldb_haystack-2.4.0-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08d854f495335511c94ab92138c2e0137436711847e11465076b179d28a5fa50
|
|
| MD5 |
f64cdbdb87979ab3058f644fc87d9d26
|
|
| BLAKE2b-256 |
2fddee68b103dc2cf62c131c2d6f695da15a3275bf5093c0ac62feb65829fe04
|
Provenance
The following attestation bundles were made for citadeldb_haystack-2.4.0-py3-none-any.whl:
Publisher:
release-haystack.yml on yp3y5akh0v/citadel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
citadeldb_haystack-2.4.0-py3-none-any.whl -
Subject digest:
08d854f495335511c94ab92138c2e0137436711847e11465076b179d28a5fa50 - Sigstore transparency entry: 2799973327
- Sigstore integration time:
-
Permalink:
yp3y5akh0v/citadel@278e8c8b00632927ad18c66a5bc52218a5f53761 -
Branch / Tag:
refs/tags/v2.4.0 - Owner: https://github.com/yp3y5akh0v
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-haystack.yml@278e8c8b00632927ad18c66a5bc52218a5f53761 -
Trigger Event:
push
-
Statement type: