Skip to main content
There are many ways to define vectors depending on the database, read the vectors documentation to know what is supported by your database.

Table with native vectors

If the table has native vectors, you can directly use them in a table without any transformation.
In ClickHouse, native vectors are called Array. Let’s create an example table with a few of them:
This table can directly be used:

Table with one column per vector element

Let’s create a table with 5 columns, each containing one element of a Quantity vector for a given product.
The table looks like this in the database: When a table has at least 2 columns with names following the pattern prefix + delimiter + number, all these columns can be converted into a single vector column (numbers must be consecutive from 0 (or 1) to N). You simply need to create a Table on this and call vectorize on it to transform this table with one column per vector element to a table with vectors. The vectorize method accepts either a list of prefixes or a delimiter to convert columns into a single vector.
In this example, both code snippets produce the same result. It is also possible to have this conversion done automatically by the discoverer. It can be enabled by setting the Discover setting useAutoVectorizer to true. With this setting enabled, the auto-vectorizer will detect columns sharing the same prefix and will convert them into a vector. The behavior of the auto-vectorization can be controlled by two more settings:
  • autoVectorizerDelimiter: sets the delimiter as defined above.
    There is no delimiter by default.
  • minThresholdForAutoVectorizer: sets minimum number of columns with the same prefix to trigger the auto-vectorization.
    The default value is 50.
With the settings set to enable the autovectorizer, there is nothing more to do after the discovery.

Table with one index and value per row

In this example we will use the following table: This table represents 2 vectors split over multiple lines. Let’s create the table and feed it.
You simply need to create a Table on this and call vectorize on it to transform this table with row by row values to a table with vectors.
You now have a table with a Vector column which will be equivalent to the following table: