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

# Retrieval

> Retrieval-Augmented Generation (RAG) is a technique that enhances large language models by retrieving relevant information from external sources before generating responses.

This approach combines the power of pre-trained models with up-to-date, domain-specific knowledge, leading to more accurate and contextually appropriate outputs. To capture the RAG pipeline, you need to log it as a "Retrieval" entity. A Retrieval represents a query that fetches relevant context from a knowledge base or vector database.

<CodeGroup>
  ```typescript JS/TS theme={null}
  const retrieval = trace.retrieval({
  	id: "retrieval-id",
  	name: "National Geographic survey report 2025.pdf",
  });

  retrieval.input("best places 2025")
  retrieval.output([
  	"Tokyo, Japan",
  	"Barcelona, Spain",
  	"Singapore",
  	"Copenhagen, Denmark",
  	"Pune, India",
  	"Seoul, South Korea",
  ])
  ```

  ```python Python theme={null}
  retrieval = trace.retrieval({
  	"id":"retrieval-id",
  	"name":"National Geographic survey report 2025.pdf",
  })
  retrieval.input("best places 2025")
  retrieval.output([
  	"Tokyo, Japan",
  	"Barcelona, Spain",
  	"Singapore",
  	"Copenhagen, Denmark",
  	"Pune, India",
  	"Seoul, South Korea",
  ])
  ```

  ```go Go theme={null}
  retrieval := span.AddRetrieval(&logging.RetrievalConfig{
  	Id:       "retrieval-id",
  	Name:     "National Geographic survey report 2025.pdf",
  })
  retrieval.SetInput("best places 2025")
  retrieval.SetOutput([]string{
  	"Tokyo, Japan",
  	"Barcelona, Spain",
  	"Singapore",
  	"Copenhagen, Denmark",
  	"Pune, India",
  	"Seoul, South Korea",
  })
  ```

  ```java Java theme={null}
  Retrieval retrieval = trace.addRetrieval(
  	new RetrievalConfig(
  		"retrieval-id",
  		"National Geographic survey report 2025.pdf"
  	)
  );

  retrieval.input("best places 2025");

  retrieval.output(Arrays.asList(
  	"Tokyo, Japan",
  	"Barcelona, Spain",
  	"Singapore",
  	"Copenhagen, Denmark",
  	"Pune, India",
  	"Seoul, South Korea",
  ));
  ```
</CodeGroup>

<Note>
  Replace 'trace.retrieval' with 'span.retrieval' when creating retrievals within an existing span
</Note>

<img src="https://mintcdn.com/maximai/fHnWe0mnvuD5228y/images/docs/tracing/via-sdk/retrieval.png?fit=max&auto=format&n=fHnWe0mnvuD5228y&q=85&s=71b2e53b87b877b9b562c08909108454" alt="Retrieval" width="2378" height="1700" data-path="images/docs/tracing/via-sdk/retrieval.png" />

<Note>[Schedule a demo](https://getmaxim.ai/demo) to see how Maxim AI helps teams ship reliable agents.</Note>
