Skip to main content

ClickHouse

Langchain Vector store for ClickHouse.

Install

pip install langchain-clickhouse

or

uv add langchain-clickhouse

Requires a running ClickHouse server (default: localhost:8123).

API Reference

__init__

def __init__(
    self,
    embedding_function: Embeddings | None = None,
    host: str = "localhost",
    port: int = 8123,
    database: str = "default",
    username: str = "default",
    password: str = "",
    table_name: str = "langchain_documents",
    **kwargs,
)
Parameter Type Description
embedding_function Embeddings | None Embedding function used to embed queries and texts (e.g., FastEmbedEmbeddings).
host str ClickHouse server host. Default "localhost".
port int ClickHouse HTTP interface port. Default 8123.
database str Database name. Default "default".
username str ClickHouse username. Default "default".
password str ClickHouse password. Default "".
table_name str Table name for storing documents. Default "langchain_documents". Created as a MergeTree 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,
    host: str | None = None,
    port: int | None = None,
    database: str | None = None,
    username: str | None = None,
    password: str | None = None,
    table_name: str | None = None,
    **kwargs,
) -> ClickHouse
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.
host str | None ClickHouse host (default: CLICKHOUSE_HOST env var or "localhost").
port int | None ClickHouse HTTP port (default: CLICKHOUSE_PORT env var or 8123).
database str | None Database name (default: CLICKHOUSE_DATABASE env var or "default").
username str | None ClickHouse username (default: CLICKHOUSE_USERNAME env var or "default").
password str | None ClickHouse password (default: CLICKHOUSE_PASSWORD env var or "").
table_name str | None Table name. Default "langchain_documents".

Returns: ClickHouse — 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, ordered by cosine similarity (descending).


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. Uses ClickHouse's native 1 - cosineDistance() for server-side ranking.

Metadata

Release files for langchain-clickhouse 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-clickhouse 0.1.0
File Size Uploaded
langchain_clickhouse-0.1.0.tar.gz 6.4 kB Details

Built distribution (wheel)

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

Total release size: 11.7 kB

Release files / langchain_clickhouse-0.1.0.tar.gz

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

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

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

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release 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