Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new vectorDistance param to hybrid query #245

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading