Skip to main content

Haystack 2.x DocumentStore for VelesDB: The Local AI Memory Database.

Project description

haystack-velesdb

A Haystack 2.x DocumentStore backed by VelesDB — the local-first, microsecond-latency vector database.

This integration joins the existing LangChain and LlamaIndex connectors, completing the trio of major Python RAG frameworks supported by VelesDB.

Installation

pip install haystack-velesdb

For development:

pip install -e "integrations/haystack[dev]"

Quick start

from haystack_velesdb import VelesDBDocumentStore
from haystack.dataclasses import Document

store = VelesDBDocumentStore(
    path="./my_docs",
    collection_name="knowledge_base",
    embedding_dim=768,
    metric="cosine",
)

# Write pre-embedded documents
documents = [
    Document(id="doc1", content="VelesDB is fast.", embedding=[0.1, 0.2, ...]),
    Document(id="doc2", content="Local-first AI memory.", embedding=[0.3, 0.4, ...]),
]
store.write_documents(documents)

# Retrieve by vector
results = store.embedding_retrieval(query_embedding=[0.1, 0.2, ...], top_k=5)
for doc in results:
    print(doc.content, doc.score)

Full RAG pipeline

See examples/rag_pipeline.py for a complete PDF ingestion and semantic search example using SentenceTransformersDocumentEmbedder.

from haystack import Pipeline
from haystack.components.converters import PyPDFToDocument
from haystack.components.embedders import (
    SentenceTransformersDocumentEmbedder,
    SentenceTransformersTextEmbedder,
)
from haystack.components.preprocessors import DocumentSplitter
from haystack.components.writers import DocumentWriter
from haystack_velesdb import VelesDBDocumentStore

store = VelesDBDocumentStore(path="./rag_store", embedding_dim=384)

# Indexing pipeline
indexer = Pipeline()
indexer.add_component("converter", PyPDFToDocument())
indexer.add_component("splitter", DocumentSplitter(split_by="sentence", split_length=3))
indexer.add_component("embedder", SentenceTransformersDocumentEmbedder(model="all-MiniLM-L6-v2"))
indexer.add_component("writer", DocumentWriter(document_store=store))
indexer.connect("converter", "splitter")
indexer.connect("splitter", "embedder")
indexer.connect("embedder", "writer")
indexer.run({"converter": {"sources": ["paper.pdf"]}})

# Query pipeline. `InMemoryEmbeddingRetriever` is bound to `InMemoryDocumentStore`
# and would NOT work against a custom DocumentStore — wrap `embedding_retrieval`
# in a thin Haystack component that forwards the call. Full working example in
# `integrations/haystack/examples/rag_pipeline.py` (`_VelesRetriever`).
from haystack import component
from haystack.dataclasses import Document
from typing import List

@component
class VelesRetriever:
    def __init__(self, document_store, top_k: int = 10):
        self._store = document_store
        self._top_k = top_k

    @component.output_types(documents=List[Document])
    def run(self, query_embedding: List[float]):
        return {"documents": self._store.embedding_retrieval(query_embedding, top_k=self._top_k)}

querier = Pipeline()
querier.add_component("embedder", SentenceTransformersTextEmbedder(model="all-MiniLM-L6-v2"))
querier.add_component("retriever", VelesRetriever(document_store=store))
querier.connect("embedder.embedding", "retriever.query_embedding")
result = querier.run({"embedder": {"text": "What is VelesDB?"}})
print(result["retriever"]["documents"])

API reference

VelesDBDocumentStore

Parameter Default Description
path "./velesdb_haystack" Directory where VelesDB persists data
collection_name "haystack_documents" VelesDB collection name
embedding_dim 768 Embedding vector dimension
metric "cosine" Distance metric: "cosine", "euclidean", or "dot"

Methods

Method Description
write_documents(documents, policy) Upsert documents; returns count written
filter_documents(filters) Scroll documents matching a VelesDB filter dict
embedding_retrieval(query_embedding, top_k, filters, scale_score) Vector similarity search
count_documents() Total document count
delete_documents(document_ids) Delete by Haystack string IDs
to_dict() / from_dict() Haystack pipeline serialisation

Note on DuplicatePolicy: NONE and OVERWRITE use VelesDB upsert semantics and always overwrite on collision. FAIL is fully enforced: a pre-scan is performed before writing and DuplicateDocumentError is raised if any document already exists (prefer OVERWRITE or NONE for bulk loads to skip the scan cost).

Note on document IDs and SHA-256: Haystack string IDs are mapped to 63-bit integers using the first 8 bytes of SHA-256 (~9.2 × 10¹⁸ slots). For a 1 M-document collection the collision probability is roughly 5 × 10⁻¹⁴, which is negligible for typical RAG workloads. A ValueError is raised at write time if a collision is detected between a new document and an existing one.

Note on scale_score: When True (default), cosine similarity scores are normalised from [-1, 1] to [0, 1] so they behave like probabilities in downstream re-ranking.

Running tests

cd integrations/haystack
pip install -e ".[dev]"
pytest tests/ -v

Tests use lightweight fake VelesDB objects — no running server required.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

haystack_velesdb-1.14.4.tar.gz (22.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

haystack_velesdb-1.14.4-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file haystack_velesdb-1.14.4.tar.gz.

File metadata

  • Download URL: haystack_velesdb-1.14.4.tar.gz
  • Upload date:
  • Size: 22.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for haystack_velesdb-1.14.4.tar.gz
Algorithm Hash digest
SHA256 fcb13b1a5f3bf5ad55b92544d947ae847ad5928e2998d82125902b20ae22cde5
MD5 d9052b053717d77e7cde86efb113d26c
BLAKE2b-256 cc450c1d7b02561ba6fa3e4c4a2f9013268d18669e9b10b5f75481ae198db1e2

See more details on using hashes here.

File details

Details for the file haystack_velesdb-1.14.4-py3-none-any.whl.

File metadata

File hashes

Hashes for haystack_velesdb-1.14.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2c01e68401bc4d070c9e8f06bb61246706c3a7f304d2ab5bbed2154543e6ecca
MD5 b65f035178369ed84528c1da3a925de1
BLAKE2b-256 381a3f60cfa8d2e9045bd4f0f1c1c5d7b4d765ed3513f3030d30cc820df642bf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page