From 79aed4a93d5db4b83f6da71895096c8d27b8305c Mon Sep 17 00:00:00 2001 From: Tommy Smith Date: Mon, 6 Jan 2025 12:59:57 +0000 Subject: [PATCH 1/2] Add new vectorDistance param to hybrid query --- src/collections/query/types.ts | 10 ++++++---- src/collections/serialize/index.ts | 1 + src/collections/serialize/unit.test.ts | 2 ++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/collections/query/types.ts b/src/collections/query/types.ts index 83080d21..5010eea2 100644 --- a/src/collections/query/types.ts +++ b/src/collections/query/types.ts @@ -103,14 +103,16 @@ export type Bm25Options = BaseBm25Options | GroupByBm25Options | undefi export type BaseHybridOptions = SearchOptions & { /** The weight of the BM25 score. If not specified, the default weight specified by the server is used. */ alpha?: number; - /** The specific vector to search for or a specific vector subsearch. If not specified, the query is vectorized and used in the similarity search. */ - vector?: NearVectorInputType | HybridNearTextSubSearch | HybridNearVectorSubSearch; - /** The properties to search in. If not specified, all properties are searched. */ - queryProperties?: (PrimitiveKeys | Bm25QueryProperty)[]; /** The type of fusion to apply. If not specified, the default fusion type specified by the server is used. */ fusionType?: 'Ranked' | 'RelativeScore'; + /** The maximum tolerated similarity in the vector search before the results are cutoff from the resultset. */ + maxVectorDistance?: number; + /** The properties to search in. If not specified, all properties are searched. */ + queryProperties?: (PrimitiveKeys | Bm25QueryProperty)[]; /** Specify which vector(s) to search on if using named vectors. */ targetVector?: TargetVectorInputType; + /** The specific vector to search for or a specific vector subsearch. If not specified, the query is vectorized and used in the similarity search. */ + vector?: NearVectorInputType | HybridNearTextSubSearch | HybridNearVectorSubSearch; }; export type HybridSubSearchBase = { diff --git a/src/collections/serialize/index.ts b/src/collections/serialize/index.ts index e8aa3f3d..b10d40f5 100644 --- a/src/collections/serialize/index.ts +++ b/src/collections/serialize/index.ts @@ -519,6 +519,7 @@ export class Serialize { alpha: args.alpha ? args.alpha : 0.5, properties: this.bm25QueryProperties(args.queryProperties), vectorBytes: vectorBytes, + vectorDistance: args.maxVectorDistance, fusionType: fusionType(args.fusionType), targetVectors, targets, diff --git a/src/collections/serialize/unit.test.ts b/src/collections/serialize/unit.test.ts index 4b3eae72..2b77505e 100644 --- a/src/collections/serialize/unit.test.ts +++ b/src/collections/serialize/unit.test.ts @@ -154,6 +154,7 @@ describe('Unit testing of Serialize', () => { vector: [1, 2, 3], targetVector: 'title', fusionType: 'Ranked', + maxVectorDistance: 0.4, supportsTargets: false, supportsVectorsForTargets: false, supportsWeightsForTargets: false, @@ -166,6 +167,7 @@ describe('Unit testing of Serialize', () => { vectorBytes: new Uint8Array(new Float32Array([1, 2, 3]).buffer), targetVectors: ['title'], fusionType: Hybrid_FusionType.FUSION_TYPE_RANKED, + vectorDistance: 0.4, }), metadata: MetadataRequest.fromPartial({ uuid: true }), }); From 04d94675d11d9fe089898bd99428c985e45bccd0 Mon Sep 17 00:00:00 2001 From: Tommy Smith Date: Mon, 13 Jan 2025 15:08:06 +0100 Subject: [PATCH 2/2] Fix typo in docstring --- src/collections/query/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/collections/query/types.ts b/src/collections/query/types.ts index 5010eea2..b3954c39 100644 --- a/src/collections/query/types.ts +++ b/src/collections/query/types.ts @@ -105,7 +105,7 @@ export type BaseHybridOptions = SearchOptions & { alpha?: number; /** The type of fusion to apply. If not specified, the default fusion type specified by the server is used. */ fusionType?: 'Ranked' | 'RelativeScore'; - /** The maximum tolerated similarity in the vector search before the results are cutoff from the resultset. */ + /** The maximum tolerated similarity in the vector search before the results are cutoff from the result set. */ maxVectorDistance?: number; /** The properties to search in. If not specified, all properties are searched. */ queryProperties?: (PrimitiveKeys | Bm25QueryProperty)[];