First time creating a connector? Read this first.
Requirements
You will need:-
A ClickHouse server that Unstructured can reach over ClickHouse’s HTTP or HTTPS interface. The connector does not use the native TCP protocol. The connector supports two kinds of deployment:
- ClickHouse Cloud: Use your service’s hostname and port
8443. Connections to ClickHouse Cloud always use TLS. - Self-managed ClickHouse (on-premises or in your own cloud account): Use your server’s hostname, plus port
8123for plain HTTP or port8443for HTTPS. If a private certificate authority (CA) signed your server’s TLS certificate, you also need that CA’s certificate as PEM text.
Timed out connecting to ClickHouse. Check the host, port, TLS setting and firewall rules. - ClickHouse Cloud: Use your service’s hostname and port
- The ClickHouse user’s name and password. If the user has no password, the password can be empty.
- The name of the database that contains the table. Database and table names cannot contain a backtick, single quote, or backslash.
-
The name of the existing table to write to.
The destination stores each element’s
metadatain aJSONcolumn. ClickHouse documents theJSONtype as production ready in open-source version 25.3 and later. The user needs theINSERT,ALTER DELETE, andALTER UPDATE(_row_exists)privileges on the table:The connector deletes a document’s earlier rows to replace them, so it needs the delete privileges.ALTER UPDATE(_row_exists)applies only to ClickHouse’s hidden column that marks deleted rows. It does not let the user change any stored data. ClickHouse Cloud 26.6 runs the connector’sDELETEas an update of that column and denies the delete without this privilege. ClickHouse 26.8 and 26.10 acceptALTER DELETEalone. The connection test requires all three privileges on every server version, because no check can tell which privileges a given server needs. (Optional) Also grantSELECTon the table. Without it, the connector cannot report how many earlier rows it replaced. -
A table that matches the following schema. The connector never creates or alters tables. You must create the table first.
The table must meet the following requirements:
- It uses the
MergeTreeengine or another engine in theMergeTreefamily, because the connector deletes rows. - It has these columns, with these types:
id(UUIDorString),record_id(String, notNullable),element_id(String),run_id(String, notNullable),text(String),type(String),embeddings(Array(Float32), notNullable), andmetadata(JSON, orStringon servers without theJSONtype). Theid,element_id,text, andtypecolumns can beNullable. TheStringcolumns can also beLowCardinality. - Any extra column has a
DEFAULTvalue, because the connector never sets it. The required columns cannot beMATERIALIZEDorALIAScolumns. - Order the table by
(record_id, element_id)so that each document’s delete does not scan the whole table.
analytics.elementswith your database and table names, and create the database first if it does not exist:To use ClickHouse for vector search, create the table with a vector similarity index on theSQLembeddingscolumn instead of using the previous statement:To add the index to a table that already exists, replaceSQLanalytics.elementswith your database and table names, and replace3072with your embedding model’s dimension. The table must use theMergeTreeorReplicatedMergeTreeengine. Then run the following statements.ADD INDEXdefines the index, andMATERIALIZE INDEXbuilds it for the rows already in the table:SQL - It uses the
How Unstructured writes to ClickHouse
When you run the workflow again, Unstructured replaces each document’s earlier rows. The connector first deletes any rows that the same run already wrote for the document’srecord_id, so a retried upload never doubles the rows.
It then inserts the document’s new rows, each tagged with the run’s run_id. Last, it deletes the earlier rows for the same record_id that have a different run_id. If a failure happens after the insert but before this delete, the old and new rows exist together until the next run. Running again fixes this.
If a document produces no rows, the connector deletes that document’s earlier rows.
If two uploads in one run have the same record_id, the later upload replaces the earlier one, because the connector first deletes the rows that the same run already wrote.
If your table has a vector index, it must meet the following requirements:
- The index dimension must equal the dimension of the embedding model in your workflow. The value
3072matches Azure OpenAItext-embedding-3-large. Use1536fortext-embedding-3-small. - The index must be on the
embeddingscolumn. The connector ignores an index on any other column. - The table must use the
MergeTreeorReplicatedMergeTreeengine. ClickHouse refuses a vector index on other engines unless the server settingallow_vector_similarity_index_in_specialized_merge_treeis on. On ClickHouse Cloud,MergeTreeworks and ClickHouse maps it to its shared engine. - The connector reads the table’s definition before it writes a document. If the table has a vector index, the connector checks every row’s embedding against the index dimension before it writes or deletes anything. If any row has an empty or different-length embedding, the document fails and the record’s earlier rows stay in place.
metadata as one JSON value and normalizes it. It drops null values, turns a dotted key such as "a.b" into nested objects, and drops nesting that goes beyond the server’s depth limit.
The following query finds the nearest rows to a query vector. Use the same distance function as the index:
Examples
To create a ClickHouse destination connector, see the following examples for ClickHouse Cloud and for a self-managed server. For more information on working with destination connectors using the Unstructured API, see Destination endpoints. To use the defaults, deletebatch_size and delete_chunk_bytes from the example.
- ClickHouse Cloud
- Self-managed
8123. For HTTPS, set port to 8443 and secure to true. If a private CA signed the server’s certificate, also set ca_cert to the CA certificate’s PEM text.
Configuration settings
Replace the preceding placeholders as follows:The ClickHouse server’s hostname or IP address, without a scheme or path. For ClickHouse Cloud, this is the service’s hostname.
The HTTP(S) interface port. Use
8443 for ClickHouse Cloud and for self-managed servers with TLS, or 8123 for a self-managed server without TLS.True to connect over HTTPS, or false to connect over plain HTTP. The default is
true. Keep this true for ClickHouse Cloud. For a self-managed server on port 8123, set it to false.The user’s password. If the user has no password, set this to an empty string and confirm that the connection test passes.
True to verify the server’s certificate, or false to skip verification. The default is
true. Set this to false only for testing.The PEM text of a private CA certificate that signed the server’s certificate. The text must contain
-----BEGIN CERTIFICATE-----. In a JSON request body, write each line break in the PEM text as \n, for example "-----BEGIN CERTIFICATE-----\n<certificate-text>\n-----END CERTIFICATE-----". Omit it if a public CA signed the certificate.The number of seconds to wait to open a connection. A paused ClickHouse Cloud service must wake up first, so raise this value if the first connection after a long idle period times out.
The maximum number of bytes of record IDs in one
DELETE statement. Allowed values are 1000 to 120000.Troubleshooting
ClickHouse rejected the username or password
ClickHouse rejected the username or password
Issue: The connection test fails with
ClickHouse rejected the username or password.Cause: The username or password does not match a ClickHouse user.Solution: Check the Username (username) and Password (password) values. If the user has no password, test with an empty Password and confirm the connection test passes.Timed out connecting to ClickHouse
Timed out connecting to ClickHouse
Issue: The connection test fails with
Timed out connecting to ClickHouse. Check the host, port, TLS setting and firewall rules.Cause: Unstructured could not open a connection to the host and port before the connect timeout expired. Possible causes:- A firewall or IP access list blocks the connection.
- The port or TLS setting does not match the server.
- A paused ClickHouse Cloud service did not wake up in time.
port) and Use TLS (secure) match your deployment (8443 with TLS, or 8123 without). Allow connections from Unstructured through any firewall or IP access list.
For ClickHouse Cloud, raise Connect timeout (s) (connect_timeout) if the first connection after a long idle period fails.Could not reach the provider
Could not reach the provider
Issue: The connection test fails with
Could not reach the provider. Check network egress, DNS, and firewall rules.Cause: The hostname does not resolve, or the host is unreachable from Unstructured.Solution: Check that Host (host) is correct, is a bare hostname, and is reachable from Unstructured.The ClickHouse settings are not valid
The ClickHouse settings are not valid
Issue: The connector fails with
The ClickHouse settings are not valid. followed by the field path and reason, for example connector_config.host: Value error, host must be a bare hostname or IP address or connector_config.ca_cert: Value error, ca_cert must be PEM text.Cause: A connection field value does not meet the connector’s validation rules.Solution: Enter only the hostname in Host (host), with no scheme (https://), path, or credentials. Paste the full PEM text, including the -----BEGIN CERTIFICATE----- line, in CA certificate (ca_cert).The destination settings are not valid
The destination settings are not valid
Issue: The connector fails with
The ClickHouse settings are not valid. followed by a field path that starts with uploader_config, such as uploader_config.delete_chunk_bytes, and the reason.Cause: Rows per insert (batch_size) is below 1, or Delete chunk size (bytes) (delete_chunk_bytes) is outside 1000 to 120000.Solution: Set Rows per insert (batch_size) to 1 or more, and Delete chunk size (bytes) (delete_chunk_bytes) to a value from 1000 to 120000.Destination table not found or no grant on it
Destination table not found or no grant on it
Issue: The connection test fails with
ClickHouse table not found, or the user has no grant on it. Create it first with these columns: id UUID, record_id String, element_id String, run_id String, text String, type String, embeddings Array(Float32), metadata JSON. This connector never creates it.Cause: The table does not exist in the database you named, or the user has no privileges on it.Solution: Create the table with the statement in Requirements, and check the Database (database) and Table (table) values. Then grant the user the privileges that the connector needs.The ClickHouse user lacks grants
The ClickHouse user lacks grants
Issue: The connection test fails with
The ClickHouse user lacks grants this connector needs on the destination table: followed by a list of privileges from INSERT, ALTER DELETE, and ALTER UPDATE(_row_exists).Cause: The user does not hold every privilege that the destination connector needs. The connection test requires all three on every server version.Solution: Replace the database, table, and user names, and then run the following statement:The ClickHouse table does not match the expected schema
The ClickHouse table does not match the expected schema
Issue: The connection test fails with
The ClickHouse table does not match the expected schema, followed by the expected columns and a list of problems. The problems can include:missing columnengine ... cannot delete rows; use a MergeTree-family enginemust not be Nullableextra column ... has no DEFAULT but this connector never sets it
DEFAULT value, and use a MergeTree-family engine.The vector index expects a different dimension
The vector index expects a different dimension
Issue: A document fails with
The table's vector index on embeddings expects <dimension>-dimensional vectors, but <bad> of <total> rows have an empty or different-length embedding. Nothing was written and the record's previous rows were kept.Cause: The workflow has no embedding node, or its embedding model produces vectors with a different number of dimensions than the table’s vector index.Solution: Add an embedding node to the workflow, or choose an embedding model whose dimension matches the index. For example, use 3072 for text-embedding-3-large and 1536 for text-embedding-3-small.
You can also create the table again with the index dimension that matches your model.ClickHouse denied the operation
ClickHouse denied the operation
Issue: The connector fails with
ClickHouse denied the operation. Check the user's grants on the database and table.Cause: The user lacks a privilege that writing to the table needs.Solution: Grant INSERT, ALTER DELETE, and ALTER UPDATE(_row_exists) on the table.ClickHouse could not find the database, table or column
ClickHouse could not find the database, table or column
Issue: The connector fails with
ClickHouse could not find the database, table or column. Check the names in the settings.Cause: A database, table, or column name is wrong.Solution: Check the Database (database) and Table (table) values.
