mirror of
https://github.com/FerretDB/documentdb.git
synced 2026-11-25 19:59:54 -05:00
### Does this PR have any customer impact? No ### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc) Feature ### Does it involve schema level changes? (Table, Column, Index, UDF, etc level changes) No ### Are you introducing any new config? If yes, do you have tests with and without them being set? Yes ### ChangeLog (Refer [Template](../oss/CHANGELOG.md)) ### Description With the release of pgvector 0.7.0, which supports [Half-Precision Indexing](https://github.com/pgvector/pgvector?tab=readme-ov-file#half-precision-indexing), vectors can have up to 4,000 dimensions ###Related GUCs **documentdb.enableVectorCompressionHalf**: enable vector compression(enabled by default) - off, disable vector compression - on, enable vector compression ###New parameters - Create index spec: "compression": string "half": half-precision vector, which using 16 bits float - Search spec: "oversampling": double Oversampling factor: Oversampling retrieval from half index to compensate for the loss of precision. Minimum value is 1. This parameter is only permitted when a compression method is used on the vector index. For example, if oversampling=1.5 and k=10, then oversampling*k=15 vectors from a compressed index. Then, the full 32-bits vector will be used for the subsequent ordering and scoring, ###Mongo Command ``` db.runCommand( { "createIndexes": "testing_vector_collection", "indexes": [{ "key": { "v": "cosmosSearch" }, "name": "hsnw_index", "cosmosSearchOptions": { "kind": "vector-hnsw", "similarity": "L2", "dimensions": 3, "compression": "half" } }] } ) ``` ``` db.testing_hnsw_vector_collection.aggregate( [ { "$search": { "cosmosSearch": { "vector": [ 3.0, 4.9, 1.0 ], "path": "vect", "filter": {"meta.a": [ { "b" : 3 } ]}, "k": 4, "efSearch": 100, "oversampling": 2.0 }, } }, { "$project": { "rank": { "$floor": [{"$multiply": [{ "$meta": "searchScore"},100000]}] } } } ]) ``` ---- #### AI description (iteration 1) #### PR Classification New feature #### PR Summary This pull request adds support for half-precision vector indexing in the vector search functionality. - `metadata_cache.c`: Added functions for half-precision vector similarity operators and functions. - `SearchTests.cs`: Added integration tests to validate half-precision vector search, including error cases and index creation scenarios. <!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
76 lines
2.1 KiB
C
76 lines
2.1 KiB
C
/*-------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
*
|
|
* include/vector/vector_common.h
|
|
*
|
|
* Common definitions for vector indexes.
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
#ifndef VECTOR_COMMON__H
|
|
#define VECTOR_COMMON__H
|
|
|
|
/* pgvector VECTOR_MAX_DIM: 16000 */
|
|
#define VECTOR_MAX_DIMENSIONS 16000
|
|
|
|
/* ivfflat parameters */
|
|
#define IVFFLAT_DEFAULT_NPROBES 1
|
|
#define IVFFLAT_MIN_NPROBES 1
|
|
#define IVFFLAT_MAX_NPROBES 32768
|
|
|
|
#define IVFFLAT_DEFAULT_LISTS 100
|
|
#define IVFFLAT_MIN_LISTS 1
|
|
#define IVFFLAT_MAX_LISTS 32768
|
|
|
|
#define VECTOR_PARAMETER_NAME_IVF_NPROBES "nProbes"
|
|
#define VECTOR_PARAMETER_NAME_IVF_NPROBES_STR_LEN 7
|
|
#define VECTOR_PARAMETER_NAME_IVF_NLISTS "numLists"
|
|
|
|
/* hnsw parameters */
|
|
#define HNSW_DEFAULT_M 16
|
|
#define HNSW_MIN_M 2
|
|
#define HNSW_MAX_M 100
|
|
|
|
#define HNSW_DEFAULT_EF_CONSTRUCTION 64
|
|
#define HNSW_MIN_EF_CONSTRUCTION 4
|
|
#define HNSW_MAX_EF_CONSTRUCTION 1000
|
|
|
|
#define HNSW_DEFAULT_EF_SEARCH 40
|
|
#define HNSW_MIN_EF_SEARCH 1
|
|
#define HNSW_MAX_EF_SEARCH 1000
|
|
|
|
#define VECTOR_PARAMETER_NAME_HNSW_M "m"
|
|
#define VECTOR_PARAMETER_NAME_HNSW_EF_CONSTRUCTION "efConstruction"
|
|
#define VECTOR_PARAMETER_NAME_HNSW_EF_SEARCH "efSearch"
|
|
#define VECTOR_PARAMETER_NAME_HNSW_EF_SEARCH_STR_LEN 8
|
|
|
|
/* dynamic calculation of nprobes or efSearch depending on collection size */
|
|
#define VECTOR_SEARCH_SMALL_COLLECTION_ROWS 10000
|
|
#define VECTOR_SEARCH_1M_COLLECTION_ROWS 1000000
|
|
|
|
/* metadata field names */
|
|
#define VECTOR_METADATA_FIELD_NAME "__cosmos_meta__"
|
|
#define VECTOR_METADATA_FIELD_NAME_STR_LEN 15
|
|
#define VECTOR_METADATA_SCORE_FIELD_NAME "score"
|
|
#define VECTOR_METADATA_SCORE_FIELD_NAME_STR_LEN 5
|
|
|
|
/*
|
|
* ApiGucPrefix.enableVectorHNSWIndex GUC determines vector indexes
|
|
* and queries are enabled in documentdb_api or not.
|
|
*/
|
|
extern bool EnableVectorHNSWIndex;
|
|
|
|
/*
|
|
* GUC to enable vector pre-filtering feature for vector search.
|
|
* This is disabled by default.
|
|
*/
|
|
extern bool EnableVectorPreFilter;
|
|
extern bool EnableVectorPreFilterV2;
|
|
|
|
/*
|
|
* GUC to enable vector compression feature for vector search.
|
|
*/
|
|
extern bool EnableVectorCompressionHalf;
|
|
|
|
#endif
|