Skip to content

Commit 06067de

Browse files
authored
Merge pull request #14429 from jkorach/gh-14428
Add TypeScript interface for the new PipelineStage - Vector Search - solving issue #14428
2 parents 3ba9778 + 580bc8c commit 06067de

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

test/types/PipelineStage.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,3 +520,20 @@ function gh12269() {
520520
}
521521
};
522522
}
523+
const vectorSearchStages: PipelineStage[] = [
524+
{
525+
$vectorSearch: {
526+
index: 'title_vector_index',
527+
path: 'embedding',
528+
queryVector: [0.522, 0.123, 0.487],
529+
limit: 5,
530+
numCandidates: 100
531+
}
532+
},
533+
{
534+
$project: {
535+
title: 1,
536+
score: { $meta: 'searchScore' }
537+
}
538+
}
539+
];

types/pipelinestage.d.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ declare module 'mongoose' {
3636
| PipelineStage.SortByCount
3737
| PipelineStage.UnionWith
3838
| PipelineStage.Unset
39-
| PipelineStage.Unwind;
39+
| PipelineStage.Unwind
40+
| PipelineStage.VectorSearch;
4041

4142
export namespace PipelineStage {
4243
export interface AddFields {
@@ -308,5 +309,17 @@ declare module 'mongoose' {
308309
/** [`$unwind` reference](https://www.mongodb.com/docs/manual/reference/operator/aggregation/unwind/) */
309310
$unwind: string | { path: string; includeArrayIndex?: string; preserveNullAndEmptyArrays?: boolean }
310311
}
312+
export interface VectorSearch {
313+
/** [`$vectorSearch` reference](https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/) */
314+
$vectorSearch: {
315+
index: string,
316+
path: string,
317+
queryVector: number[],
318+
numCandidates: number,
319+
limit: number,
320+
filter?: Expression,
321+
}
322+
}
323+
311324
}
312325
}

0 commit comments

Comments
 (0)