hybridSearch - Hybrid search
hybridSearch() combines full-text search and vector similarity search with ranking.
This API can only be used when connected with SeekdbClient. For more information about SeekdbClient, see SeekdbClient.
Prerequisites
-
You have installed seekdb-js. For more information, see Quick start.
-
You have installed the server mode of seekdb. For more information, see Deploy seekdb by using yum install.
-
You are connected to the database. For more information, see SeekdbClient.
-
You have created a collection and inserted corresponding data. For more information, see createCollection and add.
Request parameters
hybrid_search(
query={
"whereDocument": ,
"where": ,
"nResults":
},
knn={
queryEmbeddings
"queryTexts":
"where":
"nResults":
},
rank=,
nResults=,
include=
)
-
query: The full-text search configuration, which contains the following parameters:
Parameter Type Required Description Example value whereWhere No The metadata filter condition. {"category": {"$eq": "AI"}}whereDocumentWhereDocument No The document content filter condition (full-text search). {"$contains": "machine"}nResultsnumber No The number of results returned by full-text search. -
knn: The vector search configuration, which contains the following parameters:
Parameter Type Required Description Example value queryEmbeddingsnumber[] | number[][] No The single vector or vector list for batch queries. If provided, it will be used directly (ignoring embeddingFunction). If not provided, query_textmust be provided, andcollectionmust haveembeddingFunction[1.0, 2.0, 3.0] queryTextsstring | string[] No The single vector0 or vector list. If provided, it will be used directly (ignoring embeddingFunction). If not provided,documentsmust be provided, andcollectionmust haveembeddingFunction.["my query text"] whereWhere No The metadata filter condition. {"category": {"$eq": "AI"}}nResultsnumber No The number of results returned by vector search. -
Other parameters are as follows:
|Parameter|Type|Required|Description|Example value| |
rank|HybridSearchRank |No|The ranking configuration. For example:{"rrf": {"rank_window_size": 60, "rank_constant": 60}}|{"category": {"$eq": "AI"}}| |nResults|number|Yes|The number of similar results to return. Default value: 10|3| |include|readonly ("documents" | "metadatas" | "embeddings" | "distances")[]|No|The list of fields to include:["documents", "metadatas", "embeddings"].|["documents", "metadatas", "embeddings"]|
- The
embeddingFunctionused is associated with the collection (set duringcreateCollection()orgetCollection()). You cannot override it for each operation. - At least one of query or knn must be provided.
- knn:
- If
queryEmbeddingsis provided, the dimensions will be validated againstcollection.dimension. queryTexts: string or string[]; theembeddingFunctionof the collection is used to automatically embed (if the function is missing, a ValueError is returned).
- If
- If
knn.queryTextsis provided,embeddingFunctionmust be configured.
Request example
import { SeekdbClient } from "seekdb";
const client = new SeekdbClient({
host: "127.0.0.1",
port: 2881,
user: "root",
password: "",
database: "test",
});
const collection = await client.getCollection({name: 'my_collection'});
const results = await collection.hybridSearch({
query: {
whereDocument: {$contains: "machine learning"},
nResults: 10
},
knn: {
queryTexts: 'documents',
nResults: 10
},
rank: {rrf: {}},
nResults: 10
});
Response parameters
The search result dictionary, which contains the ID, distances, metadatas, document, and embeddings.