Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
FT.CREATE crea un indice ricercabile. Con Memorystore for Redis Cluster, gli indici vengono creati a livello di cluster. La creazione di un indice su un nodo comporta la creazione dell'indice su tutti i nodi del cluster.
Sintassi
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 (obbligatorio): il nome che assegni all'indice. Se esiste già un indice con lo stesso nome, viene restituito un errore.
ON HASH (facoltativo): indica il tipo di dati HASH. È supportato solo il tipo di dati HASH.
PREFIX [count] [prefix] (facoltativo): indica le chiavi hash da indicizzare.
SCHEMA hash_field_name (obbligatorio): hash_field_name dopo SCHEMA identifica il nome del campo
nell'hash. [AS alias] assegna il nome alias come alias per l'attributo
nome campo.
Tipi di campo
VECTOR (obbligatorio): campo vettoriale per la ricerca vettoriale:
[HNSW|FLAT] (obbligatorio): algoritmo designato. FLAT (brute force) o
HNSW (Hierarchical Navigable Small World).
attribute_count (obbligatorio): conteggio totale degli attributi di nomi e valori
trasmessi nella configurazione dell'algoritmo.
attribute_name attribute_value: coppie chiave-valore che definiscono
la configurazione dell'indice, ma sono specifiche di uno dei due algoritmi
disponibili.
Attributi obbligatori dell'algoritmo HNSW:
DIM (obbligatorio): conteggio delle dimensioni del vettore. I valori accettati sono 1-32768.
TYPE (obbligatorio): il tipo di vettore. È supportato solo FLOAT32.
DISTANCE_METRIC (obbligatorio): deve essere uno dei seguenti valori: L2, IP o COSINE.
Attributi facoltativi dell'algoritmo HNSW:
EF_RUNTIME (facoltativo): imposta il conteggio dei vettori da esaminare durante un'operazione di query. Il valore predefinito è 10 e il valore massimo è 4096. Puoi impostare il valore di questo parametro per ogni query che esegui. Valori più alti aumentano i tempi di query, ma migliorano il richiamo delle query.
M (facoltativo): il conteggio dei bordi in uscita massimi consentiti per ogni nodo del grafico in ogni livello. Il numero massimo di archi uscenti è 2 milioni per il livello 0. Il valore predefinito è 16. Il numero massimo è 512.
EF_CONSTRUCTION (facoltativo): imposta il conteggio dei vettori da esaminare durante la creazione dell'indice. Il valore predefinito è 200 e il valore massimo è 4096. Valori più alti aumentano il tempo necessario per creare gli indici, ma migliorano il rapporto di richiamo.
INITIAL_CAP (facoltativo): determina la capacità iniziale del vettore dell'indice. Il valore predefinito è 1024. Questo parametro determina l'allocazione della memoria dell'indice.
Attributi dell'algoritmo FLAT obbligatori:
DIM (obbligatorio): conteggio delle dimensioni del vettore.
TYPE (obbligatorio): il tipo di vettore. È supportato solo FLOAT32.
DISTANCE_METRIC (obbligatorio): deve essere uno dei seguenti valori: L2, IP o COSINE.
Attributi facoltativi dell'algoritmo FLAT:
INITIAL_CAP (facoltativo): determina la capacità iniziale del vettore dell'indice. Questo parametro determina l'allocazione della memoria dell'indice.
NUMERIC (facoltativo): campo numerico per la ricerca numerica.
TAG (facoltativo): campo tag per la ricerca basata sui tag.
SEPARATOR (facoltativo): un carattere utilizzato per dividere la stringa di tag in singoli tag. L'opzione predefinita è ,. Il valore specificato deve essere un singolo carattere. Ad esempio, la stringa di tag "hello, world" verrà interpretata come "hello" e "world" e verrà indicizzata di conseguenza. I valori consentiti sono ,.<>{}[]"':;!@#$%^&*()-+=~
CASESENSITIVE (facoltativo): indica la sensibilità alle maiuscole dei campi tag. Per impostazione predefinita, i tag non sono sensibili alle maiuscole. Una stringa di tag "HeLLo" verrà indicizzata come "hello" e una query per "Hello" e "HeLlo" produrrà lo stesso risultato.
Note
All'interno del comando FT.CREATE, gli indici VECTOR, NUMERIC e TAG possono essere visualizzati in qualsiasi sequenza.
Un campo può essere indicizzato una sola volta. Nell'esempio fornito, il campo my_vector_field_key non può essere ripetuto all'interno dello stesso indice.
In un singolo comando FT.CREATE, è possibile indicizzare un massimo di 10 campi.
Per impostazione predefinita, i TAG non distinguono tra maiuscole e minuscole.
Per impostazione predefinita, i TAG sono delimitati da ,.
Le singole query su tag e query numeriche non sono supportate. Questi campi possono essere utilizzati solo insieme alle ricerche basate su vettori.
Esempi
Esempio 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
Esempio di FLAT:
FT.CREATE my_index_name SCHEMA my_hash_field_key VECTOR Flat 8 TYPE FLOAT32 DIM 20 DISTANCE_METRIC COSINE INITIAL_CAP 15000
Esempio di HNSW con un campo numerico:
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
Esempio di HNSW con un campo 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
Esempio di HNSW con un tag e un campo numerico:
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
Esempio HNSW con più campi numerici e 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_1 TAG SEPARATOR '@' CASESENSITIVE my_numeric_field_key_1 NUMERIC my_numeric_field_key_2 NUMERIC my_tag_field_key_2 TAG
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-04 UTC."],[],[],null,["# FT.CREATE\n\n`FT.CREATE` creates a searchable index. With Memorystore for Redis Cluster, indexes are created at the cluster level. Creating an index on any node will cause creation of the index across all nodes in the cluster.\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```"]]