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

# Search overview

> Learn how LambdaDB search works, including query types, common parameters like size and consistency, field selection, sorting, and partition filtering.

A search query, or query, is a request for information about data in LambdaDB collections.

LambdaDB supports several search methods:

* Search for exact values: search for exact values or ranges of numbers, dates, IPs, or strings.
* Full-text search: use full text queries to query unstructured textual data and find documents that best match query terms.
* Vector search: store vectors in LambdaDB and use approximate nearest neighbor (ANN) to find vectors that are similar, supporting use cases like semantic search.

If you use managed embedding vector fields, see [Managed embeddings](/guides/collections/managed-embeddings) for the current supported providers and models.

Common parameters for the request body of a query are as follows:

| Parameter       | Description                                                                                                                                                          | Type      | Required | Default |
| :-------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-------- | :------- | :------ |
| size            | The number of results to return for each query                                                                                                                       | integer   | ✓        |         |
| query           | Query object (details in the [subsections](/guides/search/query-string))                                                                                             | object    | ✓        |         |
| includeVectors  | Indicates whether vector values are included in the response                                                                                                         | boolean   |          | false   |
| consistentRead  | Determines the read consistency model: If set to true, then the operation uses strongly consistent reads; otherwise, the operation uses eventually consistent reads. | boolean   |          | false   |
| fields          | A list of field names to include and/or exclude in the result. Use dot notation (e.g., user.name) to specify nested fields.                                          | object    |          |         |
| sort            | Specifies the sorting criteria for the results (details in the [subsection](/guides/search/sort))                                                                    | object\[] |          |         |
| partitionFilter | Partition filter                                                                                                                                                     | object    |          |         |

<Tip>
  Depending on your data and your query, you may get fewer than `size` results.
  This happens when `size` is larger than the number of possible matching documents for your query.
</Tip>

<Tip>
  Setting `includeVectors` (or `include_vectors` in Python) to `true` will increase response size significantly, especially for high-dimensional vectors.
  Use this option only when vector data is specifically needed for your application.
</Tip>

<Tip>
  `include` is applied first, and then `exclude` is applied to the included fields when you set both in the `fields` parameter.
</Tip>

<Note>
  LambdaDB is eventually consistent by default, so there can be a slight delay before new or changed documents are visible to queries.
  If your application requires strong (read-after-write) consistency, set `consistentRead` (or `consistent_read` in Python) to `true` when querying data from a collection, at the expense of potential higher latency and cost.
</Note>

Query results are returned in the following format:

| Field    | Description                                          | Type      |
| -------- | ---------------------------------------------------- | --------- |
| took     | Milliseconds it took LambdaDB to execute the request | long      |
| maxScore | Highest returned document `score`                    | float     |
| total    | The total number of matching documents               | long      |
| docs     | Contains returned documents and metadata             | object\[] |

## Example

<CodeGroup>
  ```python Python theme={null}
  from lambdadb import LambdaDB

  with LambdaDB(project_api_key="YOUR_API_KEY", base_url="YOUR_BASE_URL", project_name="YOUR_PROJECT_NAME") as client:
      coll = client.collection("my_collection")
      results = coll.query(query={"queryString": {"query": "*:*"}}, size=10)
      # `results.docs` contains items (each item includes `doc` and `score`).
      # `results.documents` contains document bodies only (no scores).
  ```

  <Note>
    Python: `LambdaDB` supports context manager usage. `__enter__` returns the client, and `__exit__` calls `client.close()` (closing the SDK-owned HTTP client) and makes the client unusable after the `with` block. If you don't use `with`, call `client.close()` when you're done. If you pass a custom `client=`/`async_client=`, you own closing it.
  </Note>

  ```typescript TypeScript theme={null}
  import { LambdaDBClient } from "@functional-systems/lambdadb";

  const client = new LambdaDBClient({
    projectApiKey: "YOUR_API_KEY",
    baseUrl: "YOUR_BASE_URL",
    projectName: "YOUR_PROJECT_NAME",
  });
  const results = await client.collection("my_collection").query({
    query: { queryString: { query: "*:*" } },
    size: 10,
  });
  ```

  ```go Go theme={null}
  package main

  import (
    "context"
    "log"
    lambdadb "github.com/lambdadb/go-lambdadb"
  )

  func main() {
    ctx := context.Background()
    client := lambdadb.New(
      lambdadb.WithBaseURL("YOUR_BASE_URL"),
      lambdadb.WithProjectName("YOUR_PROJECT_NAME"),
      lambdadb.WithAPIKey("YOUR_API_KEY"),
    )
    coll := client.Collection("my_collection")
    results, err := coll.Query(ctx, lambdadb.QueryCollectionInput{
      Query: map[string]interface{}{"queryString": map[string]interface{}{"query": "*:*"}},
      Size:  10,
    })
    if err != nil {
      log.Fatal(err)
    }
    _ = results
  }
  ```
</CodeGroup>

The response will look like this:

```json theme={null}
{
  "took": 76,
  "maxScore": 1.0,
  "total": 1,
  "docs": [
    {
      "collection": "example_collection",
      "score": 1.0,
      "doc": {
        "id": "33201222",
        "url": "https://en.wikipedia.org/wiki/LambdaDB",
        "title": "LambdaDB is awesome",
        "text": null
      }
    }
  ],
  "isDocsInline": true
}
```

Matched documents are ordered by similarity from most similar to least similar by default.
Similarity is expressed as a `score`, and it is calculated based on the `BM25 algorithm` for full-text search
and the configured `similarity metric` for vector search.
