Skip to main content
This page shows you how to use the fetch endpoint to fetch documents by IDs from a collection.
ParameterDescriptionTypeRequiredDefault
idsThe document IDs to fetch up to 100.string[]
includeVectorsIndicates whether vector values are included in the response. (Python: include_vectors)booleanfalse
consistentReadDetermines 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)booleanfalse
fieldsA list of field names to include and/or exclude in the result. Use dot notation (e.g., user.name) to specify nested fields.object
partitionFilterPartition filter.object
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 the document IDs (up to 100 IDs).
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"], "exclude": ["metadata.raw"]},
    )
    # `res.docs` contains items (each item includes `doc` and metadata).
    # `res.documents` contains document bodies only.
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.
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"], exclude: ["metadata.raw"] },
});
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"},
    // Optional: IncludeVectors, Fields (include/exclude)
  })
  if err != nil {
    log.Fatal(err)
  }
  _ = res
}
curl -X POST "$BASE_URL/projects/$PROJECT_NAME/collections/${collection_name}/fetch" \
  -H "Content-Type: application/json" \
  -H "x-api-key: ${YOUR_API_KEY}" \
  -d '{
    "ids": ["33201222"],
    "includeVectors": true,
    "fields": {
      "include": ["url", "title", "text"]
    }
  }'
The response will look like this:
{
  "took": 76,
  "total": 1,
  "docs": [
    {
      "collection": "example_collection",
      "doc": {
        "id": "33201222",
        "url": "https://en.wikipedia.org/wiki/LambdaDB",
        "title": "LambdaDB",
        "text": "LambdaDB is an AI-native database ... ",
        "vector": [0.6, -0.12, 0.65, 0.2, 0.3, ...]
      }
    }
  ],
  "isDocsInline": true
}
The order of the returned documents is not guaranteed to match the order of the IDs in the request.