PUT /book-index{"settings": {"index": {"number_of_shards": 3,"number_of_replicas": 1,"refresh_interval": "1s"}},"mappings": {"properties": {"id": {"type": "keyword"},"category": {"type": "keyword"},"price": {"type": "integer"},"title_text": {"type": "text"},"title_vector": {"type": "dense_vector", // Dense vector"dims": 768, // Vector dimensions"similarity": "cosine", // Vector similarity algorithm"index_options":{"type": "hnsw","m": 16, // Maximum number of connections per node in the HNSW graph"ef_construction": 100 // Number of candidate neighbors examined for each new node during HNSW construction, which affects the quality and speed of index creation}},"content_text": {"type": "text"},"content_vector": {"type": "dense_vector","dims": 768,"similarity": "cosine","index_options":{"type": "hnsw","m": 16, // Maximum number of connections per node in the HNSW graph"ef_construction": 100 // Number of candidate neighbors examined for each new node during HNSW construction, which affects the quality and speed of index creation}}}}}
Parameter | Required or Not | Description |
type | Yes | dense_vector indicates a dense vector type. |
dims | Yes | Number of vector dimensions. The maximum value is 4096. It must strictly match the dimensions of the vectors being written. Higher vector dimensions deliver richer information and higher search precision, while incurring greater storage and computational costs. You can start by testing recall/accuracy with 384 or 768 dimensions. If the results do not meet requirements, increase the dimensions; if they meet requirements, try reducing dimensions. |
similarity | Yes | Similarity calculation method, which determines the vector distance measurement standard. |
Parameter | Required or Not | Description |
type | No | Specifies the index algorithm. The default value varies across ES versions: hnsw for 8.13, int8_hnsw for 8.16, and bbq_hnsw for 9.1.3. You can set the algorithm based on the vector scale by referring to the following information: . hnsw: It is recommended for scenarios where the number of vectors is less than 100 million. . int8_hnsw: It is recommended for scenarios where the number of vectors is between 100 million and 2 billion. . bbq_hnsw: It is recommended for scenarios where the number of vectors is between 1 billion and 10 billion. . bbq_disk: It is recommended for scenarios where the number of vectors is between 1 billion and 100 billion. (diskbbq is supported in ES 9.2 and later versions, and the cloud edition is expected to be released in Q1.) |
m | No | Maximum number of connections per node in the HNSW graph, with a default value of 16. A larger m value improves recall and query speed but increases indexing time and memory usage. For most scenarios, start with 16. If extremely high recall is required and longer indexing time and larger index size are acceptable, you can try increasing it to 32 or higher. |
ef_construction | No | Number of candidate neighbors examined when connections for each new node are found during HNSW index creation, with a default value of 100. Increasing this value improves index quality and recall but prolongs index creation time. You can start with 100. If the data distribution is complex or precision requirements are high, you can set it to 200 or higher. |
Algorithm | Description |
l2_norm (Euclidean distance (L2 distance)) | Calculates the absolute spatial distance, where a smaller value indicates greater similarity. |
cosine (cosine similarity) | Focuses on vector direction and is suitable for semantic search. |
dot_product (vector dot product) | Considers both direction and magnitude. Vectors should first be normalized to unit vectors (with a length of 1). |
max_inner_product (maximum inner product) | Applies to unnormalized vectors where length carries meaningful information. |
Apakah halaman ini membantu?
Anda juga dapat Menghubungi Penjualan atau Mengirimkan Tiket untuk meminta bantuan.
masukan