Skip to main content

Cassandra

Langchain Vector store for Apache Cassandra.

Install

pip install langchain-cassandra

or

uv add langchain-cassandra

Requires a running Cassandra cluster (default: localhost:9042).

API Reference

__init__

def __init__(
    self,
    embedding_function: Embeddings | None = None,
    contact_points: list[str] | None = None,
    port: int = 9042,
    keyspace: str = "langchain",
    table_name: str = "documents",
    **kwargs,
)
Parameter Type Description
embedding_function Embeddings | None Embedding function used to embed queries and texts (e.g., FastEmbedEmbeddings).
contact_points list[str] | None Cassandra contact point hosts. Default ["localhost"].
port int Cassandra native transport port. Default 9042.
keyspace str Keyspace name. Default "langchain". Created if it doesn't exist.
table_name str Table name for storing documents. Default "documents". Created if it doesn't exist.

from_texts

def from_texts(
    cls,
    texts: list[str],
    embedding: Embeddings | None = None,
    metadatas: list[dict] | None = None,
    ids: list[str] | None = None,
    contact_points: list[str] | None = None,
    port: int | None = None,
    keyspace: str | None = None,
    table_name: str | None = None,
    **kwargs,
) -> Cassandra
Parameter Type Description
texts list[str] Texts to index.
embedding Embeddings | None Embedding function.
metadatas list[dict] | None Optional metadata dicts, one per text.
ids list[str] | None Optional document IDs. Auto-generated via SHA-256 if not provided.
contact_points list[str] | None Cassandra contact point hosts (default: CASSANDRA_HOST env var or ["localhost"]).
port int | None Cassandra native transport port (default: CASSANDRA_PORT env var or 9042).
keyspace str | None Keyspace name. Default "langchain".
table_name str | None Table name. Default "documents".

Returns: Cassandra — a new vector store with the texts indexed.


add_texts

def add_texts(
    self,
    texts: list[str],
    metadatas: list[dict] | None = None,
    ids: list[str] | None = None,
    **kwargs,
) -> list[str]
Parameter Type Description
texts list[str] Texts to add.
metadatas list[dict] | None Optional metadata dicts, one per text. Defaults to {}.
ids list[str] | None Optional document IDs. Auto-generated via SHA-256 if not provided.

Returns: list[str] — the IDs of the added texts.


delete

def delete(
    self,
    ids: list[str] | None = None,
    **kwargs,
) -> bool | None
Parameter Type Description
ids list[str] | None List of document IDs to remove.

Returns: bool — True if deletion succeeded. Raises ValueError if ids is None.


similarity_search

def similarity_search(
    self,
    query: str,
    k: int = 4,
    **kwargs,
) -> list[Document]
Parameter Type Description
query str Query text.
k int Number of documents to return. Default 4.

Returns: list[Document] — documents most similar to the query. Uses cosine similarity (fetches all embeddings, computes in-memory).


similarity_search_with_score

def similarity_search_with_score(
    self,
    query: str,
    k: int = 4,
    **kwargs,
) -> list[tuple[Document, float]]
Parameter Type Description
query str Query text.
k int Number of documents to return. Default 4.

Returns: list[tuple[Document, float]] — tuples of (Document, cosine_similarity). Score range [-1, 1]. Higher = more similar.

Metadata

Release files for langchain-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 langchain-cassandra 0.1.0
File Size Uploaded Provenance
langchain_cassandra-0.1.0.tar.gz 6.4 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 11.8 kB

Release files / langchain_cassandra-0.1.0.tar.gz

Download URL langchain_cassandra-0.1.0.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
1f39de56018b5b69ea0079621951a3fbf684d7df98c85cfda2de49c4dee0bc06
BLAKE2b-256 checksum
How to use checksums
f3deafc43e5640cbc2b835c7fbef3b3525e37f7d72e71b22bec3927239c4a0b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.17

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

Download URL langchain_cassandra-0.1.0-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c051bf252de7539b2456096f653d890fcc96bf7b1a646fc3c1f2d17f02e040dd
BLAKE2b-256 checksum
How to use checksums
3b7df00c6c658f6fb1ddf8b46a6aea26100457b946dbebff73f178a0b8515f98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.17

Security for langchain-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