Documentation Index
Fetch the complete documentation index at: https://docs.topk.io/llms.txt
Use this file to discover all available pages before exploring further.
topk-js / query_fn
Functions
bm25Score()
function bm25Score(options?: Bm25ScoreOptions): FunctionExpression;
Computes the BM25 score for a keyword search.
Parameters
| Parameter | Type |
|---|
options? | Bm25ScoreOptions |
Returns
FunctionExpression
multiVectorDistance()
function multiVectorDistance(
field: string,
query: Matrix | number[][],
candidates?: number): FunctionExpression;
Calculate the multi-vector distance between a field and a query matrix.
The query matrix can be an array of number arrays (defaults to f32),
or a Matrix instance. To specify a different matrix type,
use matrix() with valueType.
The optional candidates parameter limits the number of candidate vectors considered during retrieval.
import { field, fn, select } from "topk-js/query";
client.collection("books").query(
select({
title: field("title"),
title_distance: fn.multiVectorDistance(
"title_embedding",
[[0.1, 0.2, 0.3, ...], [0.4, 0.5, 0.6, ...]],
100
)
})
.topk(field("title_distance"), 10)
)
Parameters
| Parameter | Type |
|---|
field | string |
query | Matrix | number[][] |
candidates? | number |
Returns
FunctionExpression
semanticSimilarity()
function semanticSimilarity(field: string, query: string): FunctionExpression;
Computes the semantic similarity between a field and a query string.
Parameters
| Parameter | Type |
|---|
field | string |
query | string |
Returns
FunctionExpression
vectorDistance()
function vectorDistance(
field: string,
query:
| number[]
| List
| SparseVector
| Record<number, number>,
options?: VectorDistanceOptions): FunctionExpression;
Computes the vector distance between a field and a query vector.
Parameters
| Parameter | Type |
|---|
field | string |
query | | number[] | List | SparseVector | Record<number, number> |
options? | VectorDistanceOptions |
Returns
FunctionExpression
Interfaces
Bm25ScoreOptions
Options for BM25 scoring.
Properties
| Property | Type | Description |
|---|
b? | number | BM25 parameter b (0-1) |
k1? | number | BM25 parameter k1 (>= 0) |
VectorDistanceOptions
Properties
| Property | Type |
|---|
skipRefine? | boolean |