Skip to content

Commit d68deee

Browse files
committed
chore: Do not query for the embedding information if the validation is disabled
1 parent ed7a16e commit d68deee

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/common/search/vectorSearchEmbeddings.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ export class VectorSearchEmbeddings {
3030
database: string;
3131
collection: string;
3232
provider: NodeDriverServiceProvider;
33-
}): Promise<VectorFieldIndexDefinition[] | undefined> {
33+
}): Promise<VectorFieldIndexDefinition[]> {
34+
// We only need the embeddings for validation now, so don't query them if
35+
// validation is disabled.
36+
if (this.config.disableEmbeddingsValidation) {
37+
return [];
38+
}
39+
3440
const embeddingDefKey: EmbeddingNamespace = `${database}.${collection}`;
3541
const definition = this.embeddings.get(embeddingDefKey);
3642

@@ -61,6 +67,13 @@ export class VectorSearchEmbeddings {
6167
},
6268
document: Document
6369
): Promise<VectorFieldIndexDefinition[]> {
70+
// While we can do our best effort to ensure that the embedding validation is correct
71+
// based on https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-quantization/
72+
// it's a complex process so we will also give the user the ability to disable this validation
73+
if (this.config.disableEmbeddingsValidation) {
74+
return [];
75+
}
76+
6477
const embeddings = await this.embeddingsForNamespace({ database, collection, provider });
6578

6679
if (!embeddings) {
@@ -75,13 +88,6 @@ export class VectorSearchEmbeddings {
7588
}
7689

7790
private documentPassesEmbeddingValidation(definition: VectorFieldIndexDefinition, document: Document): boolean {
78-
// While we can do our best effort to ensure that the embedding validation is correct
79-
// based on https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-quantization/
80-
// it's a complex process so we will also give the user the ability to disable this validation
81-
if (this.config.disableEmbeddingsValidation) {
82-
return true;
83-
}
84-
8591
const fieldPath = definition.path.split(".");
8692
let fieldRef: unknown = document;
8793

0 commit comments

Comments
 (0)