11import { describe , it , expect , vi , beforeEach } from "vitest" ;
22import type { MockedFunction } from "vitest" ;
3- import { VectorSearchEmbeddings } from "../../../../src/common/search/vectorSearchEmbeddings .js" ;
3+ import { VectorSearchEmbeddingsManager } from "../../../../src/common/search/vectorSearchEmbeddingsManager .js" ;
44import type {
55 EmbeddingNamespace ,
66 VectorFieldIndexDefinition ,
7- } from "../../../../src/common/search/vectorSearchEmbeddings .js" ;
7+ } from "../../../../src/common/search/vectorSearchEmbeddingsManager .js" ;
88import { BSON } from "bson" ;
99import type { NodeDriverServiceProvider } from "@mongosh/service-provider-node-driver" ;
1010import type { ConnectionManager , UserConfig } from "../../../../src/lib.js" ;
@@ -64,7 +64,7 @@ const embeddingConfig: Map<EmbeddingNamespace, VectorFieldIndexDefinition[]> = n
6464 ] ,
6565] ) ;
6666
67- describe ( "VectorSearchEmbeddings " , ( ) => {
67+ describe ( "VectorSearchEmbeddingsManager " , ( ) => {
6868 const embeddingValidationEnabled : UserConfig = { disableEmbeddingsValidation : false } as UserConfig ;
6969 const embeddingValidationDisabled : UserConfig = { disableEmbeddingsValidation : true } as UserConfig ;
7070 const eventEmitter = new EventEmitter ( ) ;
@@ -93,7 +93,11 @@ describe("VectorSearchEmbeddings", () => {
9393 describe ( "embeddings cache" , ( ) => {
9494 it ( "the connection is closed gets cleared" , async ( ) => {
9595 const configCopy = new Map ( embeddingConfig ) ;
96- const embeddings = new VectorSearchEmbeddings ( embeddingValidationEnabled , connectionManager , configCopy ) ;
96+ const embeddings = new VectorSearchEmbeddingsManager (
97+ embeddingValidationEnabled ,
98+ connectionManager ,
99+ configCopy
100+ ) ;
97101
98102 eventEmitter . emit ( "connection-close" ) ;
99103 void embeddings ; // we don't need to call it, it's already subscribed by the constructor
@@ -144,7 +148,7 @@ describe("VectorSearchEmbeddings", () => {
144148 } ) ;
145149
146150 it ( "retrieves the list of vector search indexes for that collection from the cluster" , async ( ) => {
147- const embeddings = new VectorSearchEmbeddings ( embeddingValidationEnabled , connectionManager ) ;
151+ const embeddings = new VectorSearchEmbeddingsManager ( embeddingValidationEnabled , connectionManager ) ;
148152 const result = await embeddings . embeddingsForNamespace ( { database, collection } ) ;
149153
150154 expect ( result ) . toContainEqual ( {
@@ -156,14 +160,14 @@ describe("VectorSearchEmbeddings", () => {
156160 } ) ;
157161
158162 it ( "ignores any other type of index" , async ( ) => {
159- const embeddings = new VectorSearchEmbeddings ( embeddingValidationEnabled , connectionManager ) ;
163+ const embeddings = new VectorSearchEmbeddingsManager ( embeddingValidationEnabled , connectionManager ) ;
160164 const result = await embeddings . embeddingsForNamespace ( { database, collection } ) ;
161165
162166 expect ( result ?. filter ( ( emb ) => emb . type !== "vector" ) ) . toHaveLength ( 0 ) ;
163167 } ) ;
164168
165169 it ( "embeddings are cached in memory" , async ( ) => {
166- const embeddings = new VectorSearchEmbeddings ( embeddingValidationEnabled , connectionManager ) ;
170+ const embeddings = new VectorSearchEmbeddingsManager ( embeddingValidationEnabled , connectionManager ) ;
167171 const result1 = await embeddings . embeddingsForNamespace ( { database, collection } ) ;
168172 const result2 = await embeddings . embeddingsForNamespace ( { database, collection } ) ;
169173
@@ -172,7 +176,7 @@ describe("VectorSearchEmbeddings", () => {
172176 } ) ;
173177
174178 it ( "embeddings are cached in memory until cleaned up" , async ( ) => {
175- const embeddings = new VectorSearchEmbeddings ( embeddingValidationEnabled , connectionManager ) ;
179+ const embeddings = new VectorSearchEmbeddingsManager ( embeddingValidationEnabled , connectionManager ) ;
176180 const result1 = await embeddings . embeddingsForNamespace ( { database, collection } ) ;
177181 embeddings . cleanupEmbeddingsForNamespace ( { database, collection } ) ;
178182 const result2 = await embeddings . embeddingsForNamespace ( { database, collection } ) ;
@@ -185,7 +189,7 @@ describe("VectorSearchEmbeddings", () => {
185189
186190 describe ( "embedding validation" , ( ) => {
187191 it ( "when there are no embeddings, all documents are valid" , async ( ) => {
188- const embeddings = new VectorSearchEmbeddings (
192+ const embeddings = new VectorSearchEmbeddingsManager (
189193 embeddingValidationEnabled ,
190194 connectionManager ,
191195 new Map ( [ [ mapKey , [ ] ] ] )
@@ -197,10 +201,10 @@ describe("VectorSearchEmbeddings", () => {
197201
198202 describe ( "when there are embeddings" , ( ) => {
199203 describe ( "when the validation is disabled" , ( ) => {
200- let embeddings : VectorSearchEmbeddings ;
204+ let embeddings : VectorSearchEmbeddingsManager ;
201205
202206 beforeEach ( ( ) => {
203- embeddings = new VectorSearchEmbeddings (
207+ embeddings = new VectorSearchEmbeddingsManager (
204208 embeddingValidationDisabled ,
205209 connectionManager ,
206210 embeddingConfig
@@ -236,10 +240,10 @@ describe("VectorSearchEmbeddings", () => {
236240 } ) ;
237241
238242 describe ( "when the validation is enabled" , ( ) => {
239- let embeddings : VectorSearchEmbeddings ;
243+ let embeddings : VectorSearchEmbeddingsManager ;
240244
241245 beforeEach ( ( ) => {
242- embeddings = new VectorSearchEmbeddings (
246+ embeddings = new VectorSearchEmbeddingsManager (
243247 embeddingValidationEnabled ,
244248 connectionManager ,
245249 embeddingConfig
0 commit comments