Skip to main content

Cassandra Document Store for Haystack

PyPI version Python versions License

A Haystack document store implementation using Apache Cassandra or Astra DB as the backend.

Features

  • 📄 Full CRUD operations for documents
  • 🔍 Metadata filtering support
  • 🧮 Vector embeddings storage
  • ⚡ Prepared statements for performance
  • 🔐 Secure credential handling with Haystack Secrets
  • 📦 TTL support for automatic document expiration
  • 🏗️ Compatible with Haystack 2.x pipelines

Installation

pip install cassandra-haystack

Requires Python 3.11+ and a running Cassandra instance (or Astra DB).

Quick Start

from haystack import Document
from haystack_integrations.document_stores.cassandra import CassandraDocumentStore

# Initialize document store
document_store = CassandraDocumentStore(
    contact_points=["127.0.0.1"],  # Cassandra nodes
    port=9042,
    keyspace="haystack",
    table="documents",
)

# Write documents
docs = [
    Document(content="Hello Haystack!", meta={"source": "greeting"}),
    Document(content="Cassandra is great", meta={"source": "tech", "rating": 5}),
]
document_store.write_documents(docs)

# Filter documents
results = document_store.filter_documents(filters={"source": "tech"})
for doc in results:
    print(f"{doc.content} - {doc.meta}")

# Count documents
print(f"Total: {document_store.count_documents()}")

# Clean up
document_store.close()

Configuration

Parameter Type Default Description
contact_points List[str] ["127.0.0.1"] Cassandra node addresses
port int 9042 Cassandra port
username str/Secret None Username for auth
password str/Secret None Password for auth
keyspace str "haystack" Keyspace name
table str "documents" Table name
ttl_seconds int None Document TTL (optional)
session Session None Pre-existing session

Astra DB Support

For DataStax Astra DB, use the secure connect bundle:

from cassandra.cluster import Cluster
from cassandra.auth import PlainTextAuthProvider

cloud_config = {"secure_connect_bundle": "/path/to/secure-connect.zip"}
auth_provider = PlainTextAuthProvider("token", "AstraCS:...")
cluster = Cluster(cloud=cloud_config, auth_provider=auth_provider)
session = cluster.connect()

document_store = CassandraDocumentStore(
    session=session,
    keyspace="your_keyspace",
    table="documents"
)

Pipeline Usage

from haystack import Pipeline
from haystack.components.writers import DocumentWriter
from haystack_integrations.document_stores.cassandra import CassandraDocumentStore

document_store = CassandraDocumentStore(keyspace="haystack", table="pipeline_docs")
writer = DocumentWriter(document_store=document_store)

pipeline = Pipeline()
pipeline.add_component("writer", writer)

# Run pipeline
pipeline.run({"writer": {"documents": [Document(content="From pipeline")]}})

Schema

The store creates a table with the following schema:

CREATE TABLE documents (
    id text PRIMARY KEY,
    content text,
    metadata text,      -- JSON-encoded metadata
    embedding blob,     -- Vector embedding (optional)
    score float         -- Retrieval score (optional)
)

Development

# Install dev dependencies
pip install hatch

# Run unit tests
hatch run unit:test

# Run integration tests (requires Cassandra)
hatch run integration:test

# Run all tests
hatch run all:test

# Type checking
hatch run types:check

# Formatting
hatch run fmt:fix

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new functionality
  4. Ensure all tests pass
  5. Submit a PR

See CONTRIBUTING.md for detailed guidelines.

License

Apache 2.0 - See LICENSE.txt for details.

Metadata

Release files for haystack-cassandra 0.1.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 haystack-cassandra 0.1.0
File Size Uploaded Provenance Actions
haystack_cassandra-0.1.0.tar.gz 14.7 kB Without provenance Details for haystack_cassandra-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for haystack-cassandra 0.1.0
File Interpreter ABI Platform Actions
haystack_cassandra-0.1.0-py3-none-any.whl Python 3 none any Details for haystack_cassandra-0.1.0-py3-none-any.whl

Total release size: 31.5 kB

Release files / haystack_cassandra-0.1.0.tar.gz

Download URL haystack_cassandra-0.1.0.tar.gz
Size 14.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5045a79c9a49d87deb126161a5ffb78667b105180e2e4c2d7d4fc7bc27c409f9
BLAKE2b-256 checksum
How to use checksums
0113570674f7f41277dd95605eea8c7eb2fc7a7a40626d317787ce9d444e017e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.15

Release files / haystack_cassandra-0.1.0-py3-none-any.whl

Download URL haystack_cassandra-0.1.0-py3-none-any.whl
Size 16.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7c3950453b119558db93f31f0a5d93487a7c276f0e75beccd4b5e64339c32001
BLAKE2b-256 checksum
How to use checksums
5e6e9c1c6aa224c221c64ac08ad232bed3aa7261d8476e3c26fc6c84e4881052
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.15

Security for haystack-cassandra 0.1.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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