Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
FT.CREATE cria um índice pesquisável.
Sintaxe
FT.CREATE index
ON HASH
[PREFIX count prefix [prefix ...]]
SCHEMA field_name [AS alias] VECTOR [HNSW|FLAT] attribute_count [attribute_name attribute_value]
[field_name [AS alias] NUMERIC]
[field_name [AS alias] TAG [SEPARATOR ...] [CASESENSITIVE]]
index (obrigatório): é o nome que você dá ao índice. Se um índice com o mesmo
nome já existir, um erro será retornado.
ON HASH (opcional): indica o tipo de dados HASH. Somente o tipo de dados HASH é
compatível.
PREFIX [count] [prefix] (opcional): indica quais chaves de hash devem ser indexadas.
SCHEMA hash_field_name (obrigatório): o hash_field_name após SCHEMA identifica o nome do campo
no hash. [AS alias] atribui o nome alias como um alias para o
atributo de nome do campo.
Tipos de campo
VECTOR (obrigatório): campo vetorial para pesquisa vetorial:
[HNSW|FLAT] (obrigatório): algoritmo designado. FLAT (força bruta) ou
HNSW (Hierarchical Navigable Small World).
attribute_count (obrigatório): contagem total de atributos de nomes e valores
transmitidos na configuração do algoritmo.
attribute_name attribute_value: pares de chave-valor que definem a configuração do índice, mas são específicos para um dos dois algoritmos disponíveis.
Atributos obrigatórios do algoritmo HNSW:
DIM (obrigatório): contagem de dimensões do vetor. Os valores aceitos são 1-32768.
TYPE (obrigatório): o tipo de vetor. Somente FLOAT32 é aceito.
DISTANCE_METRIC (obrigatório): precisa ser um dos seguintes: L2, IP ou COSINE.
Atributos opcionais do algoritmo HNSW:
EF_RUNTIME (opcional): define a contagem de vetores a serem examinados durante uma operação de consulta. O padrão é 10, e o máximo é 4096. É possível definir esse valor de parâmetro para cada consulta executada. Valores mais altos aumentam os tempos de consulta, mas melhoram a recuperação da consulta.
M (opcional): a contagem máxima de arestas de saída permitidas para cada nó no gráfico em cada camada. O número máximo de arestas de saída é 2 milhões para a camada 0. O padrão é 16. O máximo é 512.
EF_CONSTRUCTION (opcional): define a contagem de vetores a serem examinados durante a construção do índice. O padrão é 200, e o máximo é 4096. Valores mais altos aumentam o tempo necessário para criar índices, mas melhoram a proporção de recuperação.
INITIAL_CAP (opcional): determina a capacidade do vetor inicial do índice. O padrão é 1024. Esse parâmetro determina a alocação de memória do índice.
Atributos obrigatórios do algoritmo FLAT:
DIM (obrigatório): contagem de dimensões do vetor.
TYPE (obrigatório): o tipo de vetor. Somente FLOAT32 é aceito.
DISTANCE_METRIC (obrigatório): precisa ser um dos seguintes: L2, IP ou COSINE.
Atributos opcionais do algoritmo FLAT:
INITIAL_CAP (opcional): determina a capacidade do vetor inicial do índice. Esse parâmetro determina a alocação de memória do índice.
NUMERIC (opcional): campo numérico para pesquisa numérica.
TAG (opcional): campo de tag para pesquisa baseada em TAG.
SEPARATOR (opcional): um caractere usado para dividir a string de tags em tags individuais. A opção padrão é ,. O valor especificado precisa ser um caractere único. Por exemplo, a string de tag "hello, world" será interpretada como "hello" e "world" e será indexada de acordo. Os valores permitidos são ,.<>{}[]"':;!@#$%^&*()-+=~
CASESENSITIVE (opcional): indica a diferenciação entre maiúsculas e minúsculas dos campos de tag. Por padrão, as tags não diferenciam maiúsculas de minúsculas. Uma string de tag "HeLLo" será indexada como "hello", e uma consulta para "Hello" e "HeLlo" vai gerar o mesmo resultado.
Observações
No comando FT.CREATE, os índices VECTOR, NUMERIC e TAG podem aparecer em qualquer sequência.
Um campo só pode ser indexado uma vez. No exemplo fornecido, o campo my_vector_field_key não pode ser repetido no mesmo índice.
Em um único comando FT.CREATE, é possível indexar no máximo 10 campos.
Por padrão, as TAGs não diferenciam maiúsculas de minúsculas.
Por padrão, as tags são delimitadas por ,.
Não é possível usar consultas individuais em tags e consultas numéricas. Esses campos só podem ser usados com pesquisas baseadas em vetores.
Exemplos
Exemplo de HNSW:
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
Exemplo de FLAT:
FT.CREATE my_index_name SCHEMA my_hash_field_key VECTOR Flat 8 TYPE FLOAT32 DIM 20 DISTANCE_METRIC COSINE INITIAL_CAP 15000
Exemplo de HNSW com um campo numérico:
FT.CREATE my_index_name SCHEMA my_vector_field_key VECTOR HNSW 10 TYPE FLOAT32 DIM 20 DISTANCE_METRIC COSINE M 4 EF_CONSTRUCTION 100 my_numeric_field_key NUMERIC
Exemplo de HNSW com um campo de tag:
FT.CREATE my_index_name SCHEMA my_vector_field_key VECTOR HNSW 10 TYPE FLOAT32 DIM 20 DISTANCE_METRIC COSINE M 4 EF_CONSTRUCTION 100 my_tag_field_key TAG SEPARATOR '@' CASESENSITIVE
Exemplo de HNSW com uma tag e um campo numérico:
FT.CREATE my_index_name SCHEMA my_vector_field_key VECTOR HNSW 10 TYPE FLOAT32 DIM 20 DISTANCE_METRIC COSINE M 4 EF_CONSTRUCTION 100 my_tag_field_key TAG SEPARATOR '@' CASESENSITIVE my_numeric_field_key NUMERIC
Exemplo de HNSW com várias tags e campos numéricos:
FT.CREATE my_index_name SCHEMA my_vector_field_key VECTOR HNSW 10 TYPE FLOAT32 DIM 20 DISTANCE_METRIC COSINE M 4 EF_CONSTRUCTION 100 my_tag_field_key_1 TAG SEPARATOR '@' CASESENSITIVE my_numeric_field_key_1 NUMERIC my_numeric_field_key_2 NUMERIC my_tag_field_key_2 TAG
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-09-05 UTC."],[],[],null,["# FT.CREATE\n\n`FT.CREATE` creates a searchable index.\n\nSyntax\n------\n\n```\nFT.CREATE index\n ON HASH\n [PREFIX count prefix [prefix ...]]\n SCHEMA field_name [AS alias] VECTOR [HNSW|FLAT] attribute_count [attribute_name attribute_value]\n [field_name [AS alias] NUMERIC]\n [field_name [AS alias] TAG [SEPARATOR ...] [CASESENSITIVE]]\n```\n\n- `index` (required): This is the name you give to your index. If an index with the same\n name exists already, an error is returned.\n\n- `ON HASH` (optional): This indicates the HASH data type. Only the HASH data type is\n supported.\n\n- `PREFIX [count] [prefix]` (optional): This indicates which hash keys to index.\n\n- `SCHEMA hash_field_name` (required): The hash_field_name after SCHEMA identifies the field name\n in the hash. `[AS alias]` assigns the name `alias` as an alias for the\n field name attribute.\n\n### Field types\n\n- `VECTOR` (required): Vector field for vector search:\n\n - `[HNSW|FLAT]` (required): Designated algorithm. Either `FLAT` (brute force) or\n HNSW (Hierarchical Navigable Small World).\n\n - `attribute_count` (required): Total attribute count of names and values\n passed in the algorithm config.\n\n - `attribute_name attribute_value`: Key-value pairs that define\n the index configuration, but are specific to one of the two available\n algorithms.\n\n - Required HNSW algorithm attributes:\n\n - `DIM` (required): Vector dimensions count. Accepted values are `1`-`32768`.\n\n - `TYPE` (required): The vector type. Only `FLOAT32` is supported.\n\n - `DISTANCE_METRIC` (required): Must be one of the following - `L2`, `IP`, or `COSINE`.\n\n - Optional HNSW algorithm attributes:\n\n - `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.\n\n - `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.\n\n - `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.\n\n - `INITIAL_CAP` (optional): Determines the starting vector capacity of the index. The default is `1024`. This parameter determines the index memory allocation.\n\n - Required FLAT algorithm attributes:\n\n - `DIM` (required): Vector dimensions count.\n\n - `TYPE` (required): The vector type. Only `FLOAT32` is supported.\n\n - `DISTANCE_METRIC` (required): Must be one of the following - `L2`, `IP`, or `COSINE`.\n\n - Optional FLAT algorithm attributes:\n\n - `INITIAL_CAP` (optional): Determines the starting vector capacity of the index. This parameter determines the index memory allocation.\n- `NUMERIC` (optional) - Numeric field for numeric search.\n\n- `TAG` (optional) - Tag field for TAG based search.\n\n - `SEPARATOR` (optional): A character utilized to divide the tag string into individual tags. The default option is `,`. The specified value must be a singular character. For example, the tag string \"hello, world\" will be interpreted as \"hello\" and \"world\" and will be indexed accordingly. Allowed values are `,.\u003c\u003e{}[]\"':;!@#$%^&*()-+=~`\n\n - `CASESENSITIVE` (optional): Denotes the case sensitivity of tag fields. By default, tags are not case-sensitive. A tag string \"HeLLo\" will be indexed as \"hello,\" and a query for \"Hello\" and \"HeLlo\" will yield the same result.\n\n### Notes\n\n- Within the FT.CREATE command, VECTOR, NUMERIC, and TAG indexes can appear in any sequence.\n\n- A field can only be indexed once. In the example provided, the field `my_vector_field_key` cannot be repeated within the same index.\n\n- In a single FT.CREATE command, a maximum of 10 fields can be indexed.\n\n- By default, TAGs are case insensitive.\n\n- By default, TAGs are delimited by `,`.\n\n- Individual queries on tag and numeric queries are not supported. These fields can only be utilized along with vector-based searches.\n\n### Examples\n\nHNSW example: \n\n```\nFT.CREATE my_index_name SCHEMA my_hash_field_key VECTOR HNSW 10 TYPE FLOAT32 DIM 20 DISTANCE_METRIC COSINE M 4 EF_CONSTRUCTION 100\n```\n\nFLAT example: \n\n```\nFT.CREATE my_index_name SCHEMA my_hash_field_key VECTOR Flat 8 TYPE FLOAT32 DIM 20 DISTANCE_METRIC COSINE INITIAL_CAP 15000\n```\n\nHNSW example with a numeric field: \n\n```\nFT.CREATE my_index_name SCHEMA my_vector_field_key VECTOR HNSW 10 TYPE FLOAT32 DIM 20 DISTANCE_METRIC COSINE M 4 EF_CONSTRUCTION 100 my_numeric_field_key NUMERIC\n```\n\nHNSW example with a tag field: \n\n```\nFT.CREATE my_index_name SCHEMA my_vector_field_key VECTOR HNSW 10 TYPE FLOAT32 DIM 20 DISTANCE_METRIC COSINE M 4 EF_CONSTRUCTION 100 my_tag_field_key TAG SEPARATOR '@' CASESENSITIVE \n```\n\nHNSW example with a tag and a numeric field: \n\n```\nFT.CREATE my_index_name SCHEMA my_vector_field_key VECTOR HNSW 10 TYPE FLOAT32 DIM 20 DISTANCE_METRIC COSINE M 4 EF_CONSTRUCTION 100 my_tag_field_key TAG SEPARATOR '@' CASESENSITIVE my_numeric_field_key NUMERIC\n```\n\nHNSW example with multiple tag and numeric fields: \n\n```\nFT.CREATE my_index_name SCHEMA my_vector_field_key VECTOR HNSW 10 TYPE FLOAT32 DIM 20 DISTANCE_METRIC COSINE M 4 EF_CONSTRUCTION 100 my_tag_field_key_1 TAG SEPARATOR '@' CASESENSITIVE my_numeric_field_key_1 NUMERIC my_numeric_field_key_2 NUMERIC my_tag_field_key_2 TAG\n```"]]