Skip to content

Commit 2eb2a55

Browse files
committed
PHPLIB-1734: Add query and model arguments for automated embedding to VectorSearchStage [skip ci]
Support the automated embedding feature introduced in MongoDB 8.2, which allows passing a natural language text query instead of a pre-computed queryVector. The $vectorSearch stage now accepts query (string) and model (string) optional arguments. Depends on mongodb/mql-specifications#55.
1 parent 5cb9d7b commit 2eb2a55

6 files changed

Lines changed: 199 additions & 15 deletions

File tree

src/Builder/Stage/FactoryTrait.php

Lines changed: 17 additions & 4 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: 17 additions & 4 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: 42 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Builder/Stage/Pipelines.php

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

tests/Builder/Stage/VectorSearchStageTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,49 @@ public function testANNFilter(): void
6464
$this->assertSamePipeline(Pipelines::VectorSearchANNFilter, $pipeline);
6565
}
6666

67+
public function testAutomatedEmbedding(): void
68+
{
69+
$pipeline = new Pipeline(
70+
Stage::vectorSearch(
71+
index: 'vector_index',
72+
limit: 10,
73+
path: 'plot_embedding',
74+
query: 'time travel',
75+
numCandidates: 150,
76+
),
77+
Stage::project(
78+
_id: 0,
79+
plot: 1,
80+
title: 1,
81+
score: ['$meta' => 'vectorSearchScore'],
82+
),
83+
);
84+
85+
$this->assertSamePipeline(Pipelines::VectorSearchAutomatedEmbedding, $pipeline);
86+
}
87+
88+
public function testAutomatedEmbeddingWithModelOverride(): void
89+
{
90+
$pipeline = new Pipeline(
91+
Stage::vectorSearch(
92+
index: 'vector_index',
93+
limit: 10,
94+
path: 'plot_embedding',
95+
query: 'time travel',
96+
model: 'voyage-3-lite',
97+
numCandidates: 150,
98+
),
99+
Stage::project(
100+
_id: 0,
101+
plot: 1,
102+
title: 1,
103+
score: ['$meta' => 'vectorSearchScore'],
104+
),
105+
);
106+
107+
$this->assertSamePipeline(Pipelines::VectorSearchAutomatedEmbeddingWithModelOverride, $pipeline);
108+
}
109+
67110
public function testENN(): void
68111
{
69112
$pipeline = new Pipeline(

0 commit comments

Comments
 (0)