Skip to main content
Version: V1.1.0

hybridSearch - Hybrid search

hybridSearch() combines full-text search and vector similarity search with ranking.

info

This API can only be used when connected with SeekdbClient. For more information about SeekdbClient, see SeekdbClient.

Prerequisites

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:

    ParameterTypeRequiredDescriptionExample value
    whereWhereNoThe metadata filter condition.{"category": {"$eq": "AI"}}
    whereDocumentWhereDocumentNoThe document content filter condition (full-text search).{"$contains": "machine"}
    nResultsnumberNoThe number of results returned by full-text search.
  • knn: The vector search configuration, which contains the following parameters:

    ParameterTypeRequiredDescriptionExample value
    queryEmbeddingsnumber[] | number[][]NoThe single vector or vector list for batch queries. If provided, it will be used directly (ignoring embeddingFunction). If not provided, query_text must be provided, and collection must have embeddingFunction[1.0, 2.0, 3.0]
    queryTextsstring | string[]NoThe single vector0 or vector list. If provided, it will be used directly (ignoring embeddingFunction). If not provided, documents must be provided, and collection must have embeddingFunction.["my query text"]
    whereWhereNoThe metadata filter condition.{"category": {"$eq": "AI"}}
    nResultsnumberNoThe 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"]|

info
  • The embeddingFunction used is associated with the collection (set during createCollection() or getCollection()). You cannot override it for each operation.
  • At least one of query or knn must be provided.
  • knn:
    • If queryEmbeddings is provided, the dimensions will be validated against collection.dimension.
    • queryTexts: string or string[]; the embeddingFunction of the collection is used to automatically embed (if the function is missing, a ValueError is returned).
  • If knn.queryTexts is provided, embeddingFunction must 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.