FT.CREATE

FT.CREATE creates a searchable index.

Syntax

FT.CREATE index
  ON HASH
  [PREFIX count prefix [prefix ...]]
  SCHEMA field_name [AS alias] VECTOR [HNSW|FLAT] attribute_count [attribute_name attribute_value])
  • index (required): This is the name you give to your index. If an index with the same name exists already, an error is returned.

  • ON HASH (optional): This indicates the HASH data type. Only the HASH data type is supported.

  • PREFIX [count] [prefix] (optional): This indicates which hash keys to index.

  • SCHEMA hash_field_name (required): The hash_field_name after SCHEMA identifies the field name in the hash. [AS alias] assigns the name alias as an alias for the field name attribute.

Field types

  • VECTOR (required): Vector field for vector search:

    • [HNSW|FLAT] (required): Designated algorithm. Either FLAT (brute force) or HNSW (Hierarchical Navigable Small World).

    • attribute_count (required): Total attribute count of names and values passed in the algorithm config.

    • attribute_name attribute_value: Key/value pairs that define the index configuration, but are specific to one of the two available algorithms.

      • Required HNSW algorithm attributes:

        • DIM (required): Vector dimensions count. Accepted values are 1-32768.

        • TYPE (required): The vector type. Only FLOAT32 is supported.

        • DISTANCE_METRIC (required): Must be one of the following - L2, IP, or COSINE.

      • Optional HNSW algorithm attributes:

        • EF_RUNTIME (optional): Sets the count of vectors to be examined during a query operation. The default is 10, and the max is 4096. You can set this parameter value for each query you run. Higher values increase query times, but improve query recall.

        • M (optional): The count of maximum permitted outgoing edges for each node in the graph in each layer. The maximum number of outgoing edges is 2M for layer 0. The Default is 16. The maximum is 512.

        • EF_CONSTRUCTION (optional): Sets count for vectors to be examined during index construction. The default is 200, and the max is 4096. Higher values increase the time needed to create indexes, but improve the recall ratio.

        • INITIAL_CAP (optional): Determines the starting vector capacity of the index. The default is 1024. This parameter determines the index memory allocation.

      • Required FLAT algorithm attributes:

        • DIM (required): Vector dimensions count.

        • TYPE (required): The vector type. Only FLOAT32 is supported.

        • DISTANCE_METRIC (required): Must be one of the following - L2, IP, or COSINE.

      • Optional FLAT algorithm attributes:

        • INITIAL_CAP (optional): Determines the starting vector capacity of the index. This parameter determines the index memory allocation.

Examples

HNSW example:

FT.CREATE my_index_name SCHEMA my_hash_field_key VECTOR HNSW 10 TYPE FLOAT32 DIM 20 DISTANCE_METRIC COSINE M 4 EF_CONSTRUCTION 100

FLAT example:

FT.CREATE my_index_name SCHEMA my_hash_field_key VECTOR Flat 8 TYPE FLOAT32 DIM 20 DISTANCE_METRIC COSINE INITIAL_CAP 15000