---
title: How to Retrieve Knowledge Base Content
description: Add knowledge base retrieval to DigitalOcean Inference requests so the model can query your private data sources with retrieval-augmented generation …
product: Inference
url: https://docs.digitalocean.com/products/inference/how-to/use-server-side-tools/retrieve-knowledge-base/
last_updated: "2026-10-16"
---

> **For AI agents:** The documentation index is at [https://docs.digitalocean.com/llms.txt](https://docs.digitalocean.com/llms.txt). Markdown versions of pages use the same URL with `index.html.md` in place of the HTML page (for example, append `index.html.md` to the directory path instead of opening the HTML document).

# How to Retrieve Knowledge Base Content

Inference provides a single control plane for managing inference workflows. It includes a Model Catalog where you can view available foundation models, including both DigitalOcean-hosted and third-party commercial models, compare model capabilities and pricing, use routing to match inference requests to the best-fit model, and run inference using serverless or dedicated deployments.

Knowledge base retrieval lets the model query your private data sources during inference using retrieval-augmented generation (RAG). You add the `knowledge_base_retrieval` tool to your API request and the inference API handles retrieval and incorporates the results into the model’s response automatically.

To use knowledge base retrieval, send a POST request with your knowledge base ID. You can find the ID in the [DigitalOcean Control Panel](https://cloud.digitalocean.com/knowledge-bases) or by querying the API. For example, use the Chat Completions API with knowledge base retrieval:

### Python

```python
import os
from pydo.inference import Client

client = Client(token=os.environ.get("MODEL_ACCESS_KEY"))

resp = client.chat.completions.create(
    model="openai-gpt-4o",
    messages=[
        {"role": "user", "content": "What are some features of DigitalOcean Inference?"},
    ],
    tools=[
        {
            "type": "knowledge_base_retrieval",
            "knowledge_base_id": "<your-knowledge-base-id>",
        }
    ],
    tool_choice="auto",
    stream=False,
    max_tokens=1024,
)

print(resp.choices[0].message.content)
```

### JavaScript

```javascript
import { InferenceClient } from "@digitalocean/dots";

const client = new InferenceClient({
    apiKey: process.env.MODEL_ACCESS_KEY,
});

const completion = await client.chat.completions.create({
    model: "openai-gpt-4o",
    messages: [
        { role: "user", content: "What are some features of DigitalOcean Inference?" },
    ],
    tools: [
        {
            type: "knowledge_base_retrieval",
            knowledge_base_id: "<your-knowledge-base-id>",
        },
    ],
    tool_choice: "auto",
    stream: false,
    max_tokens: 1024,
});

console.log(completion.choices[0].message.content);
```

### cURL

```shell
curl -X POST https://inference.do-ai.run/v1/chat/completions \
  -H "Authorization: Bearer $MODEL_ACCESS_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai-gpt-4o",
    "messages": [
      {
        "role": "user",
        "content": "What are some features of DigitalOcean Inference?"
      }
    ],
    "tools": [
      {
        "type": "knowledge_base_retrieval",
        "knowledge_base_id": "<your-knowledge-base-id>"
      }
    ],
    "tool_choice": "auto",
    "stream": false,
    "max_tokens": 1024
  }'
```

### Go

```go
package main

import (
	"context"
	"encoding/json"
	"fmt"
	"os"

	"github.com/digitalocean/godo"
)

func main() {
	client := godo.NewFromToken(os.Getenv("MODEL_ACCESS_KEY"))
	ctx := context.Background()

	completion, _, err := client.Chat.Completions.New(ctx, &godo.ChatCompletionNewParams{
		Model: "openai-gpt-4o",
		Messages: []godo.ChatCompletionMessage{
			godo.UserMessage("What are some features of DigitalOcean Inference?"),
		},
		Tools: []godo.ChatCompletionTool{
			godo.ChatKnowledgeBaseRetrievalTool("<your-knowledge-base-id>"),
		},
		ToolChoice: json.RawMessage(`"auto"`),
		MaxTokens:  godo.PtrTo(1024),
	})
	if err != nil {
		panic(err)
	}

	if msg := completion.Choices[0].Message.Content; msg != nil {
		fmt.Println(msg.Text())
	}
}
```

For the full set of parameters, see the [Serverless Inference API reference](https://docs.digitalocean.com/reference/api/reference/serverless-inference/index.html.md). The response looks like the following:

```text
{
    "choices": [
        {
            "finish_reason": "stop",
            "index": 0,
            "logprobs": null,
            "message": {
                "annotations": [
                    {
                        "type": "tool_use",
                        "tool_use": {
                            "name": "knowledge_base_retrieval",
                            "call_id": "call_y6aBCI2IrnS8ZgPR6DKjXl9T",
                            "arguments": "{\"query\":\"features of DigitalOcean Inference\"}",
                            "status": "completed",
                            "output": "{\"knowledge_base_id\":\"e7651dee-da73-11ef-bf8f-4e013e2dxxxx\",\"query\":\"features of DigitalOcean Inference\",\"results\":[{\"metadata\":{\"chunk_category\":\"CompositeElement\",\"ingested_timestamp\":\"2026-05-11T18:15:46.532085+00:00\",\"item_name\":\"https://docs.digitalocean.com/\",\"page_number\":null},\"text_content\":\"### 1 May 2026 [ ](https://docs.digitalocean.com/#1-may-2026) * The following DeepSeek model is now available on DigitalOcean Inference for [serverless inference](https://docs.digitalocean.com/products/inference/how-to/use-serverless-inference/), [Agent Development Kit](https://docs.digitalocean.com/products/inference/how-to/build-agents-using-adk/) and [agents](https://docs.digitalocean.com/products/inference/how-to/create-agents/): For more information, see the [Available Models page](https://docs.digitalocean.com/products/inference/details/models/).\"},{\"metadata\":{\"chunk_category\":\"CompositeElement\",\"ingested_timestamp\":\"2026-05-11T18:15:46.532085+00:00\",\"item_name\":\"https://docs.digitalocean.com/\",\"page_number\":null},\"text_content\":\"### 5 May 2026 [ ](https://docs.digitalocean.com/#5-may-2026) ....\"}],\"total_results\":3}"
                        }
                    }
                ],
                "content": "DigitalOcean Inference includes several features designed to support serverless inference and facilitate the development and deployment of AI models and agents. ...",
                "reasoning_content": null,
                "refusal": null,
                "role": "assistant"
            }
        }
    ],
    ...
    }
}
```

Use the Responses API with knowledge base retrieval:

```shell
curl -X POST https://inference.do-ai.run/v1/responses \
  -H "Authorization: Bearer $MODEL_ACCESS_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-v4-pro",
    "input": "What is actions infrastructure? Answer using the knowledge base.",
    "tools": [
      {
        "type": "knowledge_base_retrieval",
        "knowledge_base_id": "09d65da1-5225-11f1-b074-4e013e2dxxxx"
      }
    ],
    "stream": false,
    "max_output_tokens": 1024
  }'
```

The response looks similar to the following:

```text
{
  "background": false,
  "completed_at": 0,
  "created_at": 1779045957,
  "error": {
    "code": "",
    "message": ""
  },
  "frequency_penalty": 0,
  "id": "resp_b999e07cebb3dd7a",
  "incomplete_details": {
    "reason": ""
  },
  "instructions": {
    "OfInputItemList": null,
    "OfString": ""
  },
  "max_output_tokens": 1024,
  "max_tool_calls": 0,
  "metadata": null,
  "model": "deepseek-v4-pro",
  "object": "response",
  "output": [
    {
      "arguments": "{\"query\": \"What is actions infrastructure?\"}",
      "call_id": "chatcmpl-tool-8e9ce86361b0fe64",
      "name": "knowledge_base_retrieval",
      "status": "completed",
      "type": "function_call"
    },
    {
      "call_id": "chatcmpl-tool-8e9ce86361b0fe64",
      "output": "{\"knowledge_base_id\":\"09d65da1-5225-11f1-b074-4e013e2dxxxx\",\"query\":\"What is actions infrastructure?\",\"results\":[{\"metadata\":{\"chunk_category\":\"CompositeElement\",\"ingested_timestamp\":\"2026-05-17T19:23:20.695776+00:00\",\"item_name\":\"example-document.pdf\",\"page_number\":45},\"text_content\":\"Example content retrieved from your knowledge base.\"}],\"total_results\":1}",
      "status": "completed",
      "type": "function_call_output"
    }
  ]
}
```