> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lambdadb.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Vector query

> Run k-nearest-neighbor vector search in LambdaDB. Specify query vectors or query text, set k, apply pre-filters, and combine multi-field vector queries.

A vector query finds the k nearest vectors to a query vector or query text, as measured by a similarity metric.

## Parameters

| Parameter | Description | Type | Required |
| :- | :- | :- | :- |
| field | The name of the vector field to search against | string | ✓ |
| queryVector | Query vector you computed yourself; on a native embedding field it skips inference | float\[] | Conditionally required |
| queryText | Query text that LambdaDB embeds with a native embedding field's model | string | Conditionally required |
| queryInputs | Ordered text and image parts that LambdaDB embeds with a native embedding field's model | object\[] | Conditionally required |
| k | Number of candidates requested from this vector retrieval leg, within the [candidate limit](https://docs.lambdadb.ai/guides/get-started/limits.md#search-and-reads); top-level `size` limits final returned documents | integer | ✓ |
| filter | Query to filter the documents that can match | object | |

Provide exactly one of `queryVector`, `queryText`, or `queryInputs`. `queryText` and `queryInputs` require a native embedding vector field. Dense fields support `cosine` or `euclidean` similarity and must fit the [dimension limits](https://docs.lambdadb.ai/guides/get-started/limits.md#collections-and-schema). `queryVector` must match the field's dimensions and contain only finite numbers; cosine queries must have nonzero magnitude. The `nodeSize` parameter is not supported.

The JSON examples below are query objects: place them under the request body's `query`, alongside options such as `size`. See [Search overview](https://docs.lambdadb.ai/guides/search/search-overview.md) for complete SDK requests. When using [native reranking](https://docs.lambdadb.ai/guides/search/native-reranking.md#candidate-counts), `rerank.candidateSize` limits the merged rerank pool and does not automatically increase `k`.

## Examples

The raw-vector examples use synthetic 64-dimensional vectors and assume fields configured with `dimensions: 64`. Use your model's full query vector for real searches.

### Simple vector query

```json theme={null}
{
  "knn": {
    "field": "example_vector_field",
    "queryVector": [
      0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,
      0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,
      0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,
      0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,
      0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,
      0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,
      0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,
      0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8
    ],
    "k": 5
  }
}
```

### Native embedding vector query

Use `queryText` when the target field is a native embedding vector field. LambdaDB generates the query vector with the field's model before retrieval.

Supported providers and models are listed in [Native embeddings](https://docs.lambdadb.ai/guides/collections/native-embeddings.md).

```json theme={null}
{
  "knn": {
    "field": "bodyEmbedding",
    "queryText": "refund policy",
    "k": 5
  }
}
```

For a Cohere field, `queryInputs` combines ordered text and image parts into one query vector. An image value is a public HTTPS URL or a data URI, with the same [image limits](https://docs.lambdadb.ai/guides/collections/native-embeddings.md#image-inputs) as document writes. OpenAI fields accept a single text part.

```json theme={null}
{
  "knn": {
    "field": "embedding",
    "queryInputs": [
      { "type": "text", "value": "red shoes" },
      { "type": "image", "value": "https://example.com/shoe.png" }
    ],
    "k": 5
  }
}
```

A native embedding field also accepts `queryVector`. Use it when you already have a vector from the same model; the query then runs without inference.

### Multi-field vector query

You can search across multiple vector fields simultaneously by wrapping multiple kNN objects in a boolean query.
This is useful when you have different types of embeddings (e.g., text embedding and image embedding) and want to combine their results.

```json theme={null}
{
  "bool": [
      {
        "knn": {
          "field": "text_embedding",
          "queryVector": [
            0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,
            0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,
            0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,
            0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,
            0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,
            0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,
            0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,
            0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8
          ],
          "k": 10
        }
      },
      {
        "knn": {
          "field": "image_embedding", 
          "queryVector": [
            0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,
            0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,
            0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,
            0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,
            0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,
            0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,
            0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,
            0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8
          ],
          "k": 10
        }
      }
  ]
}
```

### Vector query with filter query

An example vector query with a filter for better performance and relevance:

```json theme={null}
{
  "knn": {
    "filter" : {
      "queryString": {
          "query": "node_type:NODE AND \"https://example.com/books/5514276\"",
          "defaultField": "metadata.url"
      }
    },
    "field": "example_vector_field",
    "queryVector": [
      0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,
      0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,
      0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,
      0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,
      0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,
      0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,
      0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,
      0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8
    ],
    "k": 5
  }
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.