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: boolTrue 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.

Download files

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

Source Distribution

langchain_cassandra-0.1.0.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

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

langchain_cassandra-0.1.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file langchain_cassandra-0.1.0.tar.gz.

File metadata

  • Download URL: langchain_cassandra-0.1.0.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.17

File hashes

Hashes for langchain_cassandra-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1f39de56018b5b69ea0079621951a3fbf684d7df98c85cfda2de49c4dee0bc06
MD5 5e4e4de7531979efe71f622045b41553
BLAKE2b-256 f3deafc43e5640cbc2b835c7fbef3b3525e37f7d72e71b22bec3927239c4a0b0

See more details on using hashes here.

File details

Details for the file langchain_cassandra-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_cassandra-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c051bf252de7539b2456096f653d890fcc96bf7b1a646fc3c1f2d17f02e040dd
MD5 ec881d004115bc428fd9ddeefc2e268d
BLAKE2b-256 3b7df00c6c658f6fb1ddf8b46a6aea26100457b946dbebff73f178a0b8515f98

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 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