Skip to content

Commit ba5c7b9

Browse files
committed
Implement $vectorSearch stage builder
1 parent df9daca commit ba5c7b9

File tree

8 files changed

+504
-2
lines changed

8 files changed

+504
-2
lines changed

generator/config/search/queryString.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ tests:
3232
-
3333
$project:
3434
_id: 0
35-
title: 1
35+
title: 1

generator/config/search/wildcard.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@ tests:
5757
-
5858
$project:
5959
_id: 0
60-
title: 1
60+
title: 1
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# $schema: ../schema.json
2+
name: $vectorSearch
3+
link: 'https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/'
4+
type:
5+
- stage
6+
encode: object
7+
description: |
8+
The $vectorSearch stage performs an ANN or ENN search on a vector in the specified field.
9+
arguments:
10+
-
11+
name: index
12+
type:
13+
- string
14+
-
15+
name: limit
16+
type:
17+
- int
18+
-
19+
name: path
20+
type:
21+
- searchPath
22+
-
23+
name: queryVector
24+
type:
25+
- array # of numbers
26+
-
27+
name: exact
28+
optional: true
29+
type:
30+
- bool
31+
-
32+
name: filter
33+
optional: true
34+
type:
35+
- query
36+
-
37+
name: numCandidates
38+
optional: true
39+
type:
40+
- int
41+
tests:
42+
-
43+
name: 'ANN Basic'
44+
link: 'https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#ann-examples'
45+
pipeline:
46+
-
47+
$vectorSearch:
48+
index: 'vector_index'
49+
path: 'plot_embedding'
50+
queryVector:
51+
- -0.0016261312
52+
- -0.028070757
53+
- -0.011342932
54+
# skip other numbers, not relevant to the test
55+
numCandidates: 150
56+
limit: 10
57+
-
58+
$project:
59+
_id: 0
60+
plot: 1
61+
title: 1
62+
score:
63+
$meta: 'vectorSearchScore'
64+
65+
-
66+
name: 'ANN Filter'
67+
link: 'https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#ann-examples'
68+
pipeline:
69+
-
70+
$vectorSearch:
71+
index: 'vector_index'
72+
path: 'plot_embedding'
73+
filter:
74+
$and:
75+
-
76+
year:
77+
$lt: 1975
78+
queryVector:
79+
- 0.02421053
80+
- -0.022372592
81+
- -0.006231137
82+
# skip other numbers, not relevant to the test
83+
numCandidates: 150
84+
limit: 10
85+
-
86+
$project:
87+
_id: 0
88+
title: 1
89+
plot: 1
90+
year: 1
91+
score:
92+
$meta: 'vectorSearchScore'
93+
94+
-
95+
name: 'ENN'
96+
link: 'https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#enn-examples'
97+
pipeline:
98+
-
99+
$vectorSearch:
100+
index: 'vector_index'
101+
path: 'plot_embedding'
102+
queryVector:
103+
- -0.006954097
104+
- -0.009932499
105+
- -0.001311474
106+
# skip other numbers, not relevant to the test
107+
exact: true
108+
limit: 10
109+
-
110+
$project:
111+
_id: 0
112+
plot: 1
113+
title: 1
114+
score:
115+
$meta: 'vectorSearchScore'

src/Builder/Stage/FactoryTrait.php

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Builder/Stage/FluentFactoryTrait.php

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Builder/Stage/VectorSearchStage.php

Lines changed: 93 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)