> ## 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

[topk-js](/sdk/topk-js/index) / query\_fn

## Functions

### bm25Score()

```ts theme={null}
function bm25Score(options?: Bm25ScoreOptions): FunctionExpression;
```

Computes the BM25 score for a keyword search.

**Parameters**

| Parameter  | Type                                                                   |
| ---------- | ---------------------------------------------------------------------- |
| `options?` | [`Bm25ScoreOptions`](/sdk/topk-js/Namespace.query_fn#bm25scoreoptions) |

**Returns**

[`FunctionExpression`](/sdk/topk-js/Namespace.query#functionexpression)

***

### multiVectorDistance()

```ts theme={null}
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`](https://docs.topk.io/sdk/topk-js/data#Matrix) instance. To specify a different matrix type,
use [`matrix()`](https://docs.topk.io/sdk/topk-js/data#matrix) with `valueType`.

The optional `candidates` parameter limits the number of candidate vectors considered during retrieval.

```javascript theme={null}
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`](/sdk/topk-js/Namespace.data#matrix) \| `number`\[]\[] |
| `candidates?` | `number`                                                         |

**Returns**

[`FunctionExpression`](/sdk/topk-js/Namespace.query#functionexpression)

***

### semanticSimilarity()

```ts theme={null}
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`](/sdk/topk-js/Namespace.query#functionexpression)

***

### vectorDistance()

```ts theme={null}
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`](/sdk/topk-js/Namespace.data#list) \| [`SparseVector`](/sdk/topk-js/Namespace.data#sparsevector) \| `Record`\<`number`, `number`> |
| `options?` | [`VectorDistanceOptions`](/sdk/topk-js/Namespace.query_fn#vectordistanceoptions)                                                                            |

**Returns**

[`FunctionExpression`](/sdk/topk-js/Namespace.query#functionexpression)

## Interfaces

### Bm25ScoreOptions

Options for BM25 scoring.

**Properties**

| Property                     | Type     | Description              |
| ---------------------------- | -------- | ------------------------ |
| <a id="property-b" /> `b?`   | `number` | BM25 parameter b (0-1)   |
| <a id="property-k1" /> `k1?` | `number` | BM25 parameter k1 (>= 0) |

***

### VectorDistanceOptions

**Properties**

| Property                                     | Type      |
| -------------------------------------------- | --------- |
| <a id="property-skiprefine" /> `skipRefine?` | `boolean` |
