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

# Fetch data

> Retrieve documents by ID from a LambdaDB collection. Supports consistent reads, vector inclusion, field filtering, and partition filters.

This page shows you how to use the fetch endpoint to fetch documents by IDs from a collection.

Large responses may return documents through `docsUrl` instead of inline `docs`. See [Large results](https://docs.lambdadb.ai/guides/search/limits#large-results) for REST download instructions and SDK behavior.

| Parameter | Description | Type | Required | Default |
| :- | :- | :- | :- | :- |
| ids | The document IDs to fetch; see [ID count limits](https://docs.lambdadb.ai/guides/get-started/limits.md#search-and-reads). | string\[] | ✓ | |
| includeVectors | Indicates whether vector values are included in the response. (Python: `include_vectors`) | 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. (Python: `consistent_read`) | 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 | | |
| partitionFilter | Partition filter. | object | | |
| ref | Branch, tag, or alias selector as `{ "kind": "...", "name": "..." }`. | object | | `main` branch |

> [!TIP]
>
> `include` is applied first, and then `exclude` is applied to the included fields when you set both in the `fields` parameter.

To fetch documents, specify their IDs within the per-request limit above.

```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")
    res = coll.docs.fetch(
        ids=["33201222"],
        include_vectors=True,
        fields={"include": ["url", "title", "text", "dense_vector"], "exclude": ["metadata.raw"]},
    )
    # `res.docs` contains items (each item includes `doc` and metadata).
    # `res.documents` contains document bodies only.
```

> [!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.

```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 res = await client.collection("my_collection").docs.fetch({
  ids: ["33201222"],
  includeVectors: true,
  fields: { include: ["url", "title", "text", "dense_vector"], exclude: ["metadata.raw"] },
});
```

```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"),
  )
  res, err := client.Collection("my_collection").Docs().Fetch(ctx, lambdadb.FetchDocsInput{
    Ids: []string{"33201222"},
    IncludeVectors: lambdadb.Bool(true),
    // Optional: Fields (include/exclude)
  })
  if err != nil {
    log.Fatal(err)
  }
  _ = res
}
```

```bash cURL theme={null}
curl -X POST "$BASE_URL/projects/$PROJECT_NAME/collections/${collection_name}/docs/fetch" \
  -H "Content-Type: application/json" \
  -H "x-api-key: ${YOUR_API_KEY}" \
  -d '{
    "ids": ["33201222"],
    "ref": { "kind": "tag", "name": "validated-2026-09" },
    "includeVectors": true,
    "fields": {
      "include": ["url", "title", "text", "dense_vector"]
    }
  }'
```

`consistentRead: true` is supported when `ref` selects a branch directly or an alias that currently targets a branch. Tag reads and an alias that targets a tag reject consistent reads. See [Branches, tags, and aliases](https://docs.lambdadb.ai/guides/data-versioning/branches-tags-aliases.md#read-from-a-ref).

Consistent reads overlay eligible pending writes. Pending bulk imports remain invisible until committed, and a pending payload above the consistent-read limit returns `429`.

The response below includes the synthetic 64-dimensional `dense_vector` from the [upsert example](https://docs.lambdadb.ai/guides/documents/upsert-data.md):

```json theme={null}
{
  "took": 76,
  "total": 1,
  "docs": [
    {
      "collection": "example_collection",
      "doc": {
        "id": "33201222",
        "url": "https://en.wikipedia.org/wiki/LambdaDB",
        "title": "LambdaDB",
        "text": "LambdaDB is a serverless search database ... ",
        "dense_vector": [
          0.015625, 0.03125, 0.046875, 0.0625, 0.078125, 0.09375, 0.109375, 0.125,
          0.140625, 0.15625, 0.171875, 0.1875, 0.203125, 0.21875, 0.234375, 0.25,
          0.265625, 0.28125, 0.296875, 0.3125, 0.328125, 0.34375, 0.359375, 0.375,
          0.390625, 0.40625, 0.421875, 0.4375, 0.453125, 0.46875, 0.484375, 0.5,
          0.515625, 0.53125, 0.546875, 0.5625, 0.578125, 0.59375, 0.609375, 0.625,
          0.640625, 0.65625, 0.671875, 0.6875, 0.703125, 0.71875, 0.734375, 0.75,
          0.765625, 0.78125, 0.796875, 0.8125, 0.828125, 0.84375, 0.859375, 0.875,
          0.890625, 0.90625, 0.921875, 0.9375, 0.953125, 0.96875, 0.984375, 1.0
        ]
      }
    }
  ],
  "isDocsInline": true
}
```

> [!NOTE]
>
> The order of the returned documents is not guaranteed to match the order of the IDs in the request.


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