Skip to content

colbert_backend

diapason.tools.storage.colbert_backend

ColBERTv2 late interaction memory backend.

Uses ColBERT's token-level embeddings with MaxSim scoring for high-quality semantic retrieval. All data lives in memory — there is no persistence across restarts.

Requires the colbert-ai and torch packages::

pip install colbert-ai torch

ColBERTMemory

Bases: MemoryBackend

In-memory ColBERTv2 late interaction retrieval backend.

Encodes queries and documents into token-level embeddings using a ColBERT checkpoint, then scores via MaxSim (for each query token, take the maximum cosine similarity across all document tokens and sum the results).

The checkpoint is lazily loaded on first use to avoid heavy model loading during import or instantiation.

clear()

Remove all stored documents.

count()

Return the number of stored documents.

delete(doc_id)

Delete a document by id. Return True if it existed.

retrieve(query, *, top_k=5, **kwargs)

Search for query and return the top-k results.

store(content, *, source='', metadata=None)

Persist content and return a unique document id.