|uuid                    |UUID                    |
---------------------------------------------------
Clickhouse table schema#
Clickhouse table will be automatically created if not exist by default. Advanced users could pre-create the table with optimized settings. For distributed Clickhouse cluster with sharding, table engine should be configured as Distributed.
print(f"Clickhouse Table DDL:\n\n{docsearch.schema}")
Clickhouse Table DDL:
CREATE TABLE IF NOT EXISTS default.clickhouse_vector_search_example(
    id Nullable(String),
    document Nullable(String),
    embedding Array(Float32),
    metadata JSON,
    uuid UUID DEFAULT generateUUIDv4(),
    CONSTRAINT cons_vec_len CHECK length(embedding) = 1536,
    INDEX vec_idx embedding TYPE annoy(100,'L2Distance') GRANULARITY 1000
) ENGINE = MergeTree ORDER BY uuid SETTINGS index_granularity = 8192
Filtering#
You can have direct access to ClickHouse SQL where statement. You can write WHERE clause following standard SQL.
NOTE: Please be aware of SQL injection, this interface must not be directly called by end-user.
If you custimized your column_map under your setting, you search with filter like this:
from langchain.vectorstores import Clickhouse, ClickhouseSettings
from langchain.document_loaders import TextLoader
loader = TextLoader('../../../state_of_the_union.txt')
documents = loader.load()
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
docs = text_splitter.split_documents(documents)
embeddings = OpenAIEmbeddings()
for i, d in enumerate(docs):
    d.metadata = {'doc_id': i}
docsearch = Clickhouse.from_documents(docs, embeddings)
Inserting data...: 100%|██████████| 42/42 [00:00<00:00, 6939.56it/s]
rtdocs_stable/api.python.langchain.com/en/stable/modules/indexes/vectorstores/examples/clickhouse.html