Metadata-Version: 2.4
Name: langchain-cassandra
Version: 0.1.0
Summary: Langchain vector store for Apache Cassandra.
Project-URL: Homepage, https://github.com/amany9000/langchain-vectorstore
Project-URL: Repository, https://github.com/amany9000/langchain-vectorstore
Project-URL: Issues, https://github.com/amany9000/langchain-vectorstore/issues
License: MIT
Requires-Python: <4.0.0,>=3.10.0
Requires-Dist: cassandra-driver<4.0.0,>=3.30.0
Requires-Dist: langchain-core<2.0.0,>=1.2.0
Description-Content-Type: text/markdown

# Cassandra

Langchain Vector store for [Apache Cassandra](https://cassandra.apache.org/).

## Install

```bash
pip install langchain-cassandra
```

or

```bash
uv add langchain-cassandra
```

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

## API Reference

### `__init__`

```python
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`

```python
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`

```python
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`

```python
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`

```python
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`

```python
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.**