mirror of
https://github.com/FerretDB/documentdb.git
synced 2026-11-25 11:49:53 -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
Adding support Product Quantization (PQ) compression in vector index, which is a popular method for dramatically compressing high-dimensional vectors to use less memory, and for making nearest-neighbor search faster.
Note: currently, this PQ compression is only supported by the Diskann index.
### Related GUCs
**documentdb.enableVectorCompressionPQ**: Enables vector PQ compression (enabled by default).
### Create index spec:
- **compression**(optional):
- "half": half-precision vector, which using 16 bits floats.
- "pq": product quantization compression.
- **pqCompressedDims**(optional): indicates the dimensions after compression. If not specified, it will be automatically calculated based on the original dimensions.
- Minimum: 1
- Maximum: 8000
- **pqSampleSize**(optional):Indicates the number of samples PQ uses to generate the initial centroids. The default value is 1000.
- Minimum: 1000
- Maximum: 100000
**Note**: It is recommended to create the index after the collection has some data.. If the collection is empty, random vectors within the range [-1, 1] are used to generate the initial centroids and create the index. If the number of documents is less than pqSampleSize, the training data is padded with random data within the range [min, max] from the sampled vector data.
### Command example
```
db.runCommand(
{ "createIndexes": "testing_vector_collection", "indexes":
[{
"key": { "v": "cosmosSearch" },
"name": "hsnw_index",
"cosmosSearchOptions":
{
"kind": "vector-diskann",
"similarity": "L2",
"dimensions": 1536,
"compression": "pq",
"pqCompressedDims": 96,
"pqSampleSize": 2000
}
}]
} )
```
### Search spec:
No changes
----
#### AI description (iteration 1)
#### PR Classification
New feature: This pull request adds support for Product Quantization (PQ) compression in the Diskann index.
#### PR Summary
This pull request introduces support for PQ compression in the Diskann index, enhancing vector search capabilities. It includes error handling for unsupported compression types and validation for PQ parameters.
- Updated `/pgmongo/src/test/regress/expected/bson_aggregation_pipeline_tests_vector_diskann.out` to include tests for PQ compression, error cases, and validation of PQ parameters such as `pqCompressedDims` and `pqSampleSize`.
- Added tests for vector search with PQ compression, including L2, cosine, and IP similarity measures.
- Implemented checks for maximum dimensions and resource limits during PQ index creation.
<!-- GitOpsUserAgent=GitOps.Apps.S...
56 lines
1.5 KiB
C
56 lines
1.5 KiB
C
/*-------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
*
|
|
* include/vector/vector_utilities.h
|
|
*
|
|
* Utility functions for computing vector scores
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
#ifndef VECTOR_UTILITIES__H
|
|
#define VECTOR_UTILITIES__H
|
|
|
|
#include <io/bson_core.h>
|
|
#include <fmgr.h>
|
|
|
|
#include "vector/vector_spec.h"
|
|
|
|
|
|
/*
|
|
* Type that holds data needed for
|
|
* computing scores vector returned from
|
|
* a vector search query. This is used to
|
|
* move required data across nodes via
|
|
* CustomScan.
|
|
*/
|
|
typedef struct SearchQueryEvalData
|
|
{
|
|
/* This contains the bson value of the search parameter,
|
|
* like { "nProbes": 4 } */
|
|
Datum SearchParamBson;
|
|
|
|
/* The access method oid of the vector index
|
|
* ivfflat/hnsw */
|
|
Oid VectorAccessMethodOid;
|
|
} SearchQueryEvalData;
|
|
|
|
|
|
double EvaluateMetaSearchScore(pgbson *document);
|
|
|
|
char * GenerateVectorIndexExprStr(const char *keyPath,
|
|
const CosmosSearchOptions *searchOptions);
|
|
|
|
Expr * GenerateVectorSortExpr(VectorSearchOptions *vectorSearchOptions,
|
|
FuncExpr *vectorCastFunc, Relation indexRelation,
|
|
Node *documentExpr, Node *vectorQuerySpecNode);
|
|
|
|
bool IsMatchingVectorIndex(Relation indexRelation, const char *queryVectorPath,
|
|
FuncExpr **vectorExtractorFunc);
|
|
|
|
Oid GetFullVectorOperatorId(VectorIndexDistanceMetric distanceMetric);
|
|
|
|
bool IsHalfVectorCastFunction(FuncExpr *vectorCastFunc);
|
|
|
|
bool IsPgvectorHalfVectorAvailable(void);
|
|
#endif
|