Skip to main content
Retrieval-Augmented Generation (RAG) systems depend on a retriever that fetches context documents before passing them to an LLM. To best evaluate RAG quality, Openlayer needs to know what context was retrieved for each request. Once context is logged, you can use tests that leverage metrics such as context recall (did the retriever surface the right information?), context relevancy (how relevant was the retrieved content to the query?), and more.

How to log context

There are two main ways to provide context to Openlayer:
The context must be passed as a list of strings (List[str]). Each string should represent a retrieved chunk/document.

1. Use @trace with context_kwarg

If your function receives the retrieved context as a keyword argument, you can tell Openlayer which argument contains it.

2. Call log_context directly

If you do not want to rely on a kwarg, or if you get the context at different points in the pipeline, you can log it explicitly: