Files
documentdb/pg_documentdb/include/vector/vector_utilities.h
T
Zinan Ren 1d3b47c814 Merged PR 1573602: [Vector] Add "exact" search parameter to enable enn search
### Does this PR have any customer impact?
Yes
### Type (Feature, Refactoring, Bugfix, DevOps, Testing, Perf, etc)
Feature, Perf
### 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?
No
### ChangeLog (Refer [Template](../oss/CHANGELOG.md))

### Description

### Introduce new field "**exact**" in vector search spec to specify whether to run ENN or ANN search.
[exact field spec](https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#fields)

### Value can be one of the following, defaults to false.
- false - to run ANN search
- true - to run ENN search

### Example
`{ "k": 1, "path": "vect", "filter": {"attr": {"$eq":1}}, "exact": true, "efSearch": 40 }`
----
#### AI description  (iteration 1)
#### PR Classification
Code enhancement for filter selectivity in vector search queries.

#### PR Summary
This pull request enhances the filter selectivity mechanism in vector search queries by adding new functions and improving existing ones.
- `bson_aggregation_vector_search.c`: Added functions to calculate filter selectivity and handle vector search options, including `AddEmptySearchParamFunctionToQuery` and `GetFilterSelectivity`.
- `index_support.c`: Added logic to identify vector search queries in the planner.
- `system_configs.c`: Introduced new configuration variables for maximum filter selectivity and document count.
- `documents_planner.c`: Enhanced planner to handle vector search queries based on selectivity.
- `vector_common.h`: Declared new configuration variables for vector filter runtime sort selectivity and document count.
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
2025-02-19 17:00:35 +08:00

52 lines
1.4 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(const char *queryVectorPath,
FuncExpr *vectorCastFunc, Relation indexRelation,
Node *documentExpr, Node *vectorQuerySpecNode,
bool exactSearch);
bool IsMatchingVectorIndex(Relation indexRelation, const char *queryVectorPath,
FuncExpr **vectorExtractorFunc);
#endif