Learn how to capture Retrieval Augmented Generation (RAG) data with LangWatch.
contexts
(retrieved documents) used by the LLM, you unlock several benefits in LangWatch:
tracer.withActiveSpan()
with type: "rag"
. Inside this span, you should perform the retrieval and then update the span with the retrieved contexts.
The contexts
should be a list of LangWatchSpanRAGContext
objects. The LangWatchSpanRAGContext
object allows you to provide more metadata about each retrieved chunk, such as document_id
, chunk_id
, and content
.
Here’s an example:
performRAG
uses tracer.withActiveSpan()
with type: "rag"
.performRAG
, we simulate a retrieval step.span.setRAGContexts(ragContexts)
is called to explicitly log the retrieved documents.generateAnswerFromContext
) is called, which itself can be another span (e.g., an LLM span).