Skip to main content

citadeldb-langchain

A LangChain VectorStore and BaseChatMessageHistory backed by Citadel. Encrypted at rest, embedded in your process, and deletes that destroy the key, not just the row.

pip install citadeldb-langchain

Requires citadeldb>=2.2,<3 and langchain-core>=0.3.22,<2.

Vector store

The example uses langchain-openai (pip install langchain-openai) and requires OPENAI_API_KEY. Text is sent to the configured embedding provider; use a local LangChain Embeddings implementation to keep embedding inference local.

from langchain_openai import OpenAIEmbeddings
from citadeldb_langchain import CitadelVectorStore

store = CitadelVectorStore(OpenAIEmbeddings(), "corpus.cdl", key="your-passphrase")

store.add_texts(["the deploy failed because the disk was full"], ids=["note-1"])
store.similarity_search("why did the release break?", k=1)

retriever = store.as_retriever(search_kwargs={"k": 4})

The width is read from your embedding model on construction, so nothing has to be configured to match it. Pass dim= to skip that probe. Models exposing model_id, model, or model_name record that identity automatically, in that order. For a custom embedding without any of those attributes, pass a stable model_id= explicitly; Citadel refuses to guess from the Python class name.

Adding an id that is already stored replaces it, so re-indexing a document does not duplicate it.

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(["note-1"])  # named ids
store.clear()  # the whole corpus

delete() with no ids is a no-op. Use clear() to empty the store.

Filters

store.similarity_search("...", k=4, filter={"source": "handbook.pdf"})

Filters narrow candidates before final top-k selection.

MMR selection runs inside Citadel over the exact vectors stored for the recalled candidates. Stored vectors do not cross the Python boundary, and the document embedding model is not run again during search.

retriever = store.as_retriever(
    search_type="mmr",
    search_kwargs={"k": 4, "fetch_k": 20, "lambda_mult": 0.5},
)

Chat history

Chat history reads complete sessions by id. This example uses local e5-large and requires the Candle source build and model setup. The default wheel accepts a bring-your-own semantic embedder.

import citadeldb
from citadeldb_langchain import CitadelChatMessageHistory

embedder = citadeldb.CandleEmbedder("/path/to/e5-large", preset="e5-large")
history = CitadelChatMessageHistory(
    "user-123",
    "chats.cdl",
    key="your-passphrase",
    embedder=embedder,
)
history.add_user_message("remember my dog is called Mochi")
history.messages

Messages round-trip through LangChain's own serialization, so tool calls, block content and additional_kwargs all survive. clear() destroys each message's key, so a cleared conversation is unreadable.

Use it with RunnableWithMessageHistory the same way as any other history:

import citadeldb
from langchain_core.runnables.history import RunnableWithMessageHistory

chain = RunnableWithMessageHistory(
    runnable,  # your chain
    lambda session_id: CitadelChatMessageHistory(
        session_id,
        "chats.cdl",
        key="your-passphrase",
        embedder=embedder,
    ),
    input_messages_key="input",
    history_messages_key="history",
)

Notes

Citadel is embedded and one process owns the file. A path already open on this thread, under the same passphrase, is shared, so the vector store and the chat history can sit on one encrypted database; construct them on the same thread.

A custom chat-history embedder must expose dim, metric, model_id, and embed_with_cancel(texts, cancel_token). Accept None as the token; otherwise check it between bounded batches. An asymmetric model can also provide embed_queries_with_cancel.

License

Apache-2.0

Metadata

Release files for citadeldb-langchain 2.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for citadeldb-langchain 2.7.0
File Size Uploaded
citadeldb_langchain-2.7.0.tar.gz 16.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for citadeldb-langchain 2.7.0
File Interpreter ABI Platform
citadeldb_langchain-2.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 27.9 kB

Release files / citadeldb_langchain-2.7.0.tar.gz

Download URL citadeldb_langchain-2.7.0.tar.gz
Size 16.9 kB
Tags Source
SHA-256 checksum
How to use checksums
0a91a0926c25753676583dcb82d8aa6dbb07fd4be308760cde4b0862c9c38723
BLAKE2b-256 checksum
How to use checksums
66c33dd718fda9c82c1c176c0fa5de9e8553067035021a7d0ab08185bf6ed11d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 28, 2026.

Transparency log

Release files / citadeldb_langchain-2.7.0-py3-none-any.whl

Download URL citadeldb_langchain-2.7.0-py3-none-any.whl
Size 10.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0bb9dea288535ca1e6a5369fe9bb93d82a8debc9dac5f72700d984238b4e1a0b
BLAKE2b-256 checksum
How to use checksums
dd8ed53944a2c79051be59b3dc83971b2c09f3ae63a893b3ae17960ac0e26926
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 28, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

2.7.0 This release

2 release files

2.6.1

2 release files

2.6.0

2 release files

2.5.0

2 release files

2.4.0

2 release files

2.3.0

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page