Skip to content

Commit

Permalink
Merge pull request #245 from weaviate/#198/add-max-vector-distance-to…
Browse files Browse the repository at this point in the history
…-query

Add new vectorDistance param to hybrid query
  • Loading branch information
tsmith023 authored Jan 13, 2025
2 parents 3164cfd + 04d9467 commit a254718
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/collections/query/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,16 @@ export type Bm25Options<T> = BaseBm25Options<T> | GroupByBm25Options<T> | undefi
export type BaseHybridOptions<T> = SearchOptions<T> & {
/** 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<T> | Bm25QueryProperty<T>)[];
/** 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 result set. */
maxVectorDistance?: number;
/** The properties to search in. If not specified, all properties are searched. */
queryProperties?: (PrimitiveKeys<T> | Bm25QueryProperty<T>)[];
/** 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 = {
Expand Down
1 change: 1 addition & 0 deletions src/collections/serialize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/collections/serialize/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 }),
});
Expand Down

0 comments on commit a254718

Please sign in to comment.