Learn how to capture retrieved context so RAG-specific metrics can be computed in Openlayer
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.
{"docsConfig":{"theme":"aspen","$schema":"https://mintlify.com/docs.json","name":"Openlayer","colors":{"primary":"#592FEA","light":"#7A58EE","dark":"#7A58EE"},"logo":{"light":"https://mintcdn.com/openlayer-docs/j8aCq8ZxFTiWgvd7/logo/logo-docs-brand.svg?fit=max\u0026auto=format\u0026n=j8aCq8ZxFTiWgvd7\u0026q=85\u0026s=e33e9c38c5e338a9df337ef2c11c1d12","dark":"https://mintcdn.com/openlayer-docs/j8aCq8ZxFTiWgvd7/logo/logo-docs-brand-dark.svg?fit=max\u0026auto=format\u0026n=j8aCq8ZxFTiWgvd7\u0026q=85\u0026s=55cba7faebfb90304a52071092233014","href":"https://openlayer.com"},"favicon":"https://mintcdn.com/openlayer-docs/V8WkhV9OB3C8n0Xk/favicon.svg?fit=max\u0026auto=format\u0026n=V8WkhV9OB3C8n0Xk\u0026q=85\u0026s=abe75e70e20a31a0c2b99b49d2ae158b","api":{"openapi":["api-reference/openapi.yaml"],"playground":{"display":"none"},"mdx":{"auth":{"method":"bearer"},"server":"https://api.openlayer.com/v1"}},"appearance":{"default":"system"},"background":{"color":{"light":"#FFFFFF","dark":"#000000"}},"navbar":{"links":[{"href":"https://discord.gg/t6wS2g6MMB","label":"Community"},{"href":"https://app.openlayer.com/?login=true","label":"Log in"}],"primary":{"type":"button","label":"Get started","href":"https://app.openlayer.com/"}},"footer":{"socials":{"discord":"https://discord.gg/t6wS2g6MMB","linkedin":"https://www.linkedin.com/company/openlayerco","twitter":"https://twitter.com/openlayerco"}},"fonts":{"family":"Inter"},"icons":{"library":"lucide"},"integrations":{"mixpanel":{"projectToken":"401ce9e4de4663c33009eb3d140d3945"}},"styling":{"latex":false},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"openlayer-docs","hasAudioNarration":false,"actualSubdomain":"openlayer-docs","customDomains":["openlayer.com"],"gitSource":{"type":"github","owner":"openlayer-ai","repo":"openlayer-docs","deployBranch":"main","contentDirectory":"","isPrivate":false,"mountPath":"","label":""},"chroma":{"liveDeploymentHistoryId":"6ae4f027fdba3191e694fdfc","collectionId":"35cd4217-1309-4f74-89dc-481c5193d587","schemaVersion":"v3","latestBuiltDeploymentHistoryId":"6ae4f027fdba3191e694fdfc"},"feedback":{"thumbs":true,"edits":true,"issues":true},"entitlements":{"AI_CHAT":{"status":"ENABLED"},"WEB_MCP":{"status":"ENABLED"},"NARRATION":{"status":"ENABLED"}},"buildId":"6ae4f027fdba3191e694fdfc","clientVersion":"0.0.4043","searchFilterCounts":[{"language":"default","tag":"Documentation","count":196},{"language":"default","tag":"Tests","count":122},{"language":"default","tag":"Catalog","count":111},{"language":"default","tag":"Reference","count":91},{"language":"default","tag":"REST API","count":64},{"language":"default","tag":"Integrations","count":61},{"language":"default","tag":"Governance","count":35},{"language":"default","tag":"Observability","count":23},{"language":"default","tag":"CLI","count":19},{"language":"default","tag":"Commands","count":17}]},"assistantConfig":{},"basePath":"/docs","hasChatPermissions":true,"hasWebMcpPermissions":true,"toggles":[],"googleFontsInlined":false},"customCss":[],"page":{"pagePath":"monitoring/context","slug":"/monitoring/context","pageMetadata":{"title":"Log context for RAG systems","description":"Learn how to capture retrieved context so RAG-specific metrics can be computed in Openlayer","href":"/monitoring/context"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Learn how to capture retrieved context so RAG-specific metrics can be computed in Openlayer\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={code:`code`,em:`em`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,..._provideComponents(),...props.components},{CodeBlock,Heading,Note}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Note)_missingMdxReference(`Note`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[`Retrieval-Augmented Generation (RAG) systems depend on a `,_jsx(_components.strong,{children:`retriever`}),` that fetches\ncontext documents before passing them to an LLM.\nTo best evaluate RAG quality, Openlayer needs to know `,_jsx(_components.em,{children:`what context was retrieved`}),` for each request.`]}),`\n`,_jsxs(_components.p,{children:[`Once context is logged, you can use tests that leverage metrics such as `,_jsx(_components.strong,{children:`context recall`}),` (did the retriever surface the right information?),\n`,_jsx(_components.strong,{children:`context relevancy`}),` (how relevant was the retrieved content to the query?), and more.`]}),`\n`,_jsx(Heading,{level:`2`,id:`how-to-log-context`,children:`How to log context`}),`\n`,_jsx(_components.p,{children:`There are two main ways to provide context to Openlayer:`}),`\n`,_jsx(Note,{children:_jsxs(_components.p,{children:[`The context must be passed as a `,_jsx(_components.strong,{children:`list of strings`}),` (`,_jsx(_components.code,{children:`List[str]`}),`). Each string\nshould represent a retrieved chunk/document.`]})}),`\n`,_jsxs(Heading,{level:`3`,id:`1-use-@trace-with-context_kwarg`,children:[`1. Use `,_jsx(_components.code,{children:`@trace`}),` with `,_jsx(_components.code,{children:`context_kwarg`})]}),`\n`,_jsx(_components.p,{children:`If your function receives the retrieved context as a keyword argument, you can\ntell Openlayer which argument contains it.`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`5`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`5`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` openlayer.lib `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` trace`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`@trace`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`context_kwarg`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"context\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` generate_answer`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`query`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`context`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: list[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]) -> `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` llm_call(query, context)`})]}),`\n`]})})}),`\n`,_jsxs(Heading,{level:`3`,id:`2-call-log_context-directly`,children:[`2. Call `,_jsx(_components.code,{children:`log_context`}),` directly`]}),`\n`,_jsx(_components.p,{children:`If you do not want to rely on a kwarg, or if you get the context at\ndifferent points in the pipeline, you can log it explicitly:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`10`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`10`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` openlayer.lib `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` trace`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` openlayer.lib.tracing `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` log_context`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`@trace`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`()`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` generate_answer`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`query`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) -> `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`str`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` context `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` retrieve_context(query)`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:` # Log the retrieved context manually`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` log_context(context)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` llm_call(query, context)`})]}),`\n`]})})})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"Log context for RAG systems","description":"Learn how to capture retrieved context so RAG-specific metrics can be computed in Openlayer","href":"/monitoring/context"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"How to log context","slug":"how-to-log-context","depth":2,"children":[{"title":"1. Use @trace with context_kwarg","slug":"1-use-@trace-with-context_kwarg","depth":3,"children":[]},{"title":"2. Call log_context directly","slug":"2-call-log_context-directly","depth":3,"children":[]}]}],"codeExamples":{}},"jsLinks":["/docs/_mintlify/custom/openlayer-docs/a85e4a0a43b4a6e9/.eslintrc.js"],"subdomain":"openlayer-docs","siteName":"Openlayer","title":"Log context for RAG systems - Openlayer","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-07-08T12:48:14.596Z","originalFileLocation":"monitoring/context.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Learn how to capture retrieved context so RAG-specific metrics can be computed in Openlayer\">\u003cmeta data-mint-head name=\"application-name\" content=\"Openlayer\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/docs/mintlify-assets/_mintlify/favicons/openlayer-docs/JkuoDa5Uvs4Y0n-U/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/docs/mintlify-assets/_mintlify/favicons/openlayer-docs/JkuoDa5Uvs4Y0n-U/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/docs/mintlify-assets/_mintlify/favicons/openlayer-docs/JkuoDa5Uvs4Y0n-U/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/docs/mintlify-assets/_mintlify/favicons/openlayer-docs/JkuoDa5Uvs4Y0n-U/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/docs/mintlify-assets/_mintlify/favicons/openlayer-docs/JkuoDa5Uvs4Y0n-U/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/docs/mintlify-assets/_mintlify/favicons/openlayer-docs/JkuoDa5Uvs4Y0n-U/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/docs/mintlify-assets/_mintlify/favicons/openlayer-docs/JkuoDa5Uvs4Y0n-U/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/docs/mintlify-assets/_mintlify/favicons/openlayer-docs/JkuoDa5Uvs4Y0n-U/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/docs/mintlify-assets/_mintlify/favicons/openlayer-docs/JkuoDa5Uvs4Y0n-U/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Log context for RAG systems - Openlayer\">\u003cmeta data-mint-head property=\"og:description\" content=\"Learn how to capture retrieved context so RAG-specific metrics can be computed in Openlayer\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Openlayer\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://openlayer.com/docs/monitoring/context\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://openlayer-docs.mintlify.app/_mintlify/api/og/v2?division=Enrich+traces\u0026amp;title=Log+context+for+RAG+systems\u0026amp;description=Learn+how+to+capture+retrieved+context+so+RAG-specific+metrics+can+be+computed+in+Openlayer\u0026amp;theme=d15cfd1a18d9f87a0af36cb6\u0026amp;signature=102821c357388741f1c002f3f2b553013ac7aa71cc0ac71cc56a39ff085bddc9\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Log context for RAG systems - Openlayer\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Learn how to capture retrieved context so RAG-specific metrics can be computed in Openlayer\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://openlayer-docs.mintlify.app/_mintlify/api/og/v2?division=Enrich+traces\u0026amp;title=Log+context+for+RAG+systems\u0026amp;description=Learn+how+to+capture+retrieved+context+so+RAG-specific+metrics+can+be+computed+in+Openlayer\u0026amp;theme=d15cfd1a18d9f87a0af36cb6\u0026amp;signature=102821c357388741f1c002f3f2b553013ac7aa71cc0ac71cc56a39ff085bddc9\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/docs/mintlify-assets/_mintlify/favicons/openlayer-docs/JkuoDa5Uvs4Y0n-U/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Openlayer\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#592FEA\">\u003clink data-mint-head rel=\"canonical\" href=\"https://openlayer.com/docs/monitoring/context\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/docs/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/docs/monitoring/context.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://openlayer.com/#organization\",\"name\":\"Openlayer\",\"url\":\"https://openlayer.com\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/openlayer-docs/j8aCq8ZxFTiWgvd7/logo/logo-docs-brand.svg?fit=max\u0026auto=format\u0026n=j8aCq8ZxFTiWgvd7\u0026q=85\u0026s=e33e9c38c5e338a9df337ef2c11c1d12\"}},{\"@type\":\"WebSite\",\"@id\":\"https://openlayer.com/docs#website\",\"name\":\"Openlayer\",\"url\":\"https://openlayer.com/docs\",\"publisher\":{\"@id\":\"https://openlayer.com/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://openlayer.com/docs/monitoring/context#webpage\",\"url\":\"https://openlayer.com/docs/monitoring/context\",\"name\":\"Log context for RAG systems\",\"description\":\"Learn how to capture retrieved context so RAG-specific metrics can be computed in Openlayer\",\"dateModified\":\"2026-07-08T12:48:14.596Z\",\"isPartOf\":{\"@id\":\"https://openlayer.com/docs#website\"},\"breadcrumb\":{\"@id\":\"https://openlayer.com/docs/monitoring/context#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://openlayer.com/docs/monitoring/context#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Observability\",\"item\":\"https://openlayer.com/docs/monitoring/overview\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Enrich traces\",\"item\":\"https://openlayer.com/docs/monitoring/metadata\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Log context for RAG systems\",\"item\":\"https://openlayer.com/docs/monitoring/context\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://openlayer.com/docs/monitoring/context#article\",\"headline\":\"Log context for RAG systems\",\"name\":\"Log context for RAG systems\",\"description\":\"Learn how to capture retrieved context so RAG-specific metrics can be computed in Openlayer\",\"url\":\"https://openlayer.com/docs/monitoring/context\",\"mainEntityOfPage\":{\"@id\":\"https://openlayer.com/docs/monitoring/context#webpage\"},\"dateModified\":\"2026-07-08T12:48:14.596Z\",\"publisher\":{\"@id\":\"https://openlayer.com/#organization\"},\"isPartOf\":{\"@id\":\"https://openlayer.com/docs#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Openlayer\",\"creator\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","siteName":"Openlayer","nav":{"global":null,"tabs":[{"tab":"Documentation","groups":[{"group":"Get started","pages":[{"title":"Introduction","mode":"wide","icon":"album","href":"/introduction"}]},{"group":"Workspace setup","pages":[{"title":"Workspace dashboard","icon":"layout-dashboard","href":"/workspace-and-projects/workspace-dashboard"},{"group":"Projects","icon":"folder","pages":[{"title":"Create a project","hidden":false,"href":"/workspace-and-projects/creating-and-loading-projects"},{"title":"Project dashboards","href":"/workspace-and-projects/project-dashboards"}]},{"title":"Create an API key","icon":"key-round","href":"/workspace-and-projects/find-your-api-key"}]},{"group":"Governance","pages":[{"title":"Overview","icon":"landmark","hidden":false,"href":"/governance/overview"},{"group":"Set up a framework","icon":"rocket","pages":[{"title":"Activate a built-in framework","hidden":false,"href":"/governance/activate-framework"},{"title":"Build a custom framework","hidden":false,"href":"/governance/build-custom-framework"}]},{"group":"Understand requirements","icon":"book-open-check","pages":[{"title":"How frameworks map to requirements","hidden":false,"href":"/governance/framework-requirements"},{"title":"Platform rules","hidden":false,"href":"/governance/platform-rules"},{"title":"Evidence-based rules","hidden":false,"href":"/governance/evidence-based-rules"}]},{"group":"Track compliance","icon":"chart-bar","pages":[{"title":"Track compliance across your workspace","hidden":false,"href":"/governance/workspace-compliance"},{"title":"Track compliance within a project","hidden":false,"href":"/governance/project-compliance"},{"title":"Use the governance API","href":"/governance/api-access"}]},{"title":"Define intake and risk forms","icon":"clipboard-list","href":"/governance/intake-and-risk-forms"},{"title":"Project lifecycle","icon":"refresh-cw","href":"/governance/project-lifecycle"}]},{"group":"Observability","pages":[{"title":"Overview","icon":"telescope","href":"/monitoring/overview"},{"group":"Integrate","icon":"user-cog","pages":[{"title":"Instrument your code","hidden":false,"href":"/monitoring/instrument"},{"title":"Other integration paths","href":"/monitoring/alternative-integrations"}]},{"group":"Enrich traces","icon":"grid-2x2-plus","pages":[{"title":"Add metadata to traces","href":"/monitoring/metadata"},{"title":"Custom columns","href":"/monitoring/custom-columns"},{"title":"Trace multimodal data","href":"/monitoring/multimodal"},{"title":"Track users and sessions","description":"Track multi-turn journeys and individual behavior in your Openlayer traces","href":"/monitoring/sessions-and-users"},{"title":"Log context for RAG systems","href":"/monitoring/context"},{"title":"Redact PII","description":"Redact personally identifiable information from trace data before it is stored","href":"/monitoring/pii-redaction"},{"title":"Log question for RAG systems","href":"/monitoring/question"},{"title":"Update existing traces","href":"/monitoring/updating-data"}]},{"group":"Beyond traces","icon":"binoculars","pages":[{"title":"Publish traditional ML predictions","href":"/monitoring/publishing-tabular-predictions"},{"title":"Upload a reference dataset","href":"/monitoring/uploading-reference-dataset"}]},{"group":"Concepts","icon":"book-open","pages":[{"title":"Evaluation and delay windows","href":"/monitoring/evaluation-and-delay-windows"},{"title":"LLM cost estimation","href":"/monitoring/cost-estimation"}]},{"group":"Guardrails","icon":"shield-alert","pages":[{"title":"Overview","hidden":false,"href":"/guardrails/overview"}]},{"title":"AI-generated summaries","icon":"sparkles","href":"/monitoring/ai-summaries"},{"title":"Export data","icon":"download","href":"/monitoring/export-data"}]},{"group":"Offline testing","pages":[{"title":"Overview","icon":"git-commit-vertical","href":"/development/overview"},{"group":"Integrate","icon":"user-cog","pages":[{"title":"Push and poll using the Openlayer CLI","href":"/guides/cli-push"}]},{"group":"Configure","icon":"braces","pages":[{"title":"openlayer.json","href":"/development/openlayer-json"},{"title":"tests.json","href":"/development/tests-json"},{"title":"Configuring output generation","href":"/development/configuring-output-generation"}]},{"group":"Custom CI/CD setups","icon":"git-compare","pages":[{"title":"GitHub Actions with Openlayer","href":"/guides/gh-actions"}]}]},{"group":"Tests","pages":[{"title":"Overview","hidden":false,"icon":"list-checks","href":"/tests/overview"},{"title":"Browse tests","mode":"frame","icon":"scan-search","href":"/tests/browse"},{"group":"Catalog","icon":"notebook","pages":[{"title":"Accuracy","hidden":false,"href":"/tests/catalog/accuracy"},{"title":"Aggregate metrics","hidden":false,"href":"/tests/catalog/aggregate-metrics"},{"title":"Anomalous column count","hidden":false,"href":"/tests/catalog/anomalous-column-count"},{"title":"Answer correctness","hidden":false,"href":"/tests/catalog/answer-correctness"},{"title":"Answer relevancy","hidden":false,"href":"/tests/catalog/answer-relevancy"},{"title":"Bias","hidden":false,"href":"/tests/catalog/bias"},{"title":"BLEU score","hidden":false,"href":"/tests/catalog/bleu-score"},{"title":"Character length","hidden":false,"href":"/tests/catalog/character-length"},{"title":"Class imbalance ratio","hidden":false,"href":"/tests/catalog/class-imbalance-ratio"},{"title":"Coherence","hidden":false,"href":"/tests/catalog/coherence"},{"title":"Column average","hidden":false,"href":"/tests/catalog/column-average"},{"title":"Column drift","hidden":false,"href":"/tests/catalog/column-drift"},{"title":"Column freshness","href":"/tests/catalog/column-freshness"},{"title":"Column statistics","hidden":false,"href":"/tests/catalog/column-statistic"},{"title":"Column values match","hidden":false,"href":"/tests/catalog/column-values-match"},{"title":"Conciseness","hidden":false,"href":"/tests/catalog/conciseness"},{"title":"Conflicting labels","hidden":false,"href":"/tests/catalog/conflicting-label-count"},{"title":"Contains PII","hidden":false,"href":"/tests/catalog/contains-p-i-i"},{"title":"Valid URLs","hidden":false,"href":"/tests/catalog/contains-valid-url"},{"title":"Context recall","hidden":false,"href":"/tests/catalog/context-recall"},{"title":"Context relevancy","hidden":false,"href":"/tests/catalog/context-relevancy"},{"title":"Context utilization","hidden":false,"href":"/tests/catalog/context-utilization"},{"title":"Correctness","hidden":false,"href":"/tests/catalog/correctness"},{"title":"Correlated features","hidden":false,"href":"/tests/catalog/correlated-feature-count"},{"title":"Data type validation","hidden":false,"href":"/tests/catalog/dtype-validation"},{"title":"Duplicate rows","hidden":false,"href":"/tests/catalog/duplicate-count"},{"title":"Edit distance","hidden":false,"href":"/tests/catalog/edit-distance"},{"title":"Empty features","hidden":false,"href":"/tests/catalog/empty-feature"},{"title":"Empty feature count","hidden":false,"href":"/tests/catalog/empty-feature-count"},{"title":"Exact match","hidden":false,"href":"/tests/catalog/exact-match"},{"title":"Column contains string","hidden":false,"href":"/tests/catalog/expect-column-a-to-be-in-column-b"},{"title":"F1 score","hidden":false,"href":"/tests/catalog/f1"},{"title":"Faithfulness","hidden":false,"href":"/tests/catalog/faithfulness"},{"title":"False positive rate","hidden":false,"href":"/tests/catalog/false-positive-rate"},{"title":"Feature drift","hidden":false,"href":"/tests/catalog/feature-drift-count"},{"title":"Feature values","hidden":false,"href":"/tests/catalog/feature-values"},{"title":"Features missing values","hidden":false,"href":"/tests/catalog/features-missing-values"},{"title":"Freshness","href":"/tests/catalog/freshness"},{"title":"Geometric mean","hidden":false,"href":"/tests/catalog/geometric-mean"},{"title":"Great expectations","hidden":false,"href":"/tests/catalog/great-expectations"},{"title":"Groundedness","hidden":false,"href":"/tests/catalog/groundedness"},{"title":"Group by column statistic","hidden":false,"href":"/tests/catalog/group-by-column-statistic"},{"title":"Group metric parity","href":"/tests/catalog/group-metric-parity"},{"title":"Group outcome disparity","href":"/tests/catalog/group-outcome-disparity"},{"title":"Group performance parity","href":"/tests/catalog/group-performance-parity"},{"title":"Group score disparity","href":"/tests/catalog/group-score-disparity"},{"title":"Hallucination","hidden":false,"href":"/tests/catalog/hallucination"},{"title":"Harmfulness","hidden":false,"href":"/tests/catalog/harmfulness"},{"title":"Has prompt injection","hidden":false,"href":"/tests/catalog/has-prompt-injection-count"},{"title":"Ill-formed rows","hidden":false,"href":"/tests/catalog/ill-formed-count"},{"title":"Is code","hidden":false,"href":"/tests/catalog/is-code"},{"title":"Is JSON","hidden":false,"href":"/tests/catalog/is-json"},{"title":"Jev-as-a-judge","href":"/tests/catalog/jev-as-a-judge-threshold"},{"title":"JSON score","hidden":false,"href":"/tests/catalog/json-score"},{"title":"LLM-as-a-judge","hidden":false,"href":"/tests/catalog/l-l-m-rubric-threshold"},{"title":"Label/target drift","hidden":false,"href":"/tests/catalog/label-drift"},{"title":"Log loss","hidden":false,"href":"/tests/catalog/log-loss"},{"title":"Mean absolute error (MAE)","hidden":false,"href":"/tests/catalog/mae"},{"title":"Maliciousness","hidden":false,"href":"/tests/catalog/maliciousness"},{"title":"Mean absolute percentage error (MAPE)","hidden":false,"href":"/tests/catalog/mape"},{"title":"Max cost","hidden":false,"href":"/tests/catalog/max-cost"},{"title":"Max latency","hidden":false,"href":"/tests/catalog/max-latency"},{"title":"Max tokens","hidden":false,"href":"/tests/catalog/max-tokens"},{"title":"Mean cost","hidden":false,"href":"/tests/catalog/mean-cost"},{"title":"Mean latency","hidden":false,"href":"/tests/catalog/mean-latency"},{"title":"Mean tokens","hidden":false,"href":"/tests/catalog/mean-tokens"},{"title":"Median latency","hidden":false,"href":"/tests/catalog/median-latency"},{"title":"Min latency","hidden":false,"href":"/tests/catalog/min-latency"},{"title":"Mean squared error (MSE)","hidden":false,"href":"/tests/catalog/mse"},{"title":"New categories","hidden":false,"href":"/tests/catalog/new-category-count"},{"title":"New labels","hidden":false,"href":"/tests/catalog/new-label-count"},{"title":"Null rows","hidden":false,"href":"/tests/catalog/null-count"},{"title":"90th latency percentile","hidden":false,"href":"/tests/catalog/p90-latency"},{"title":"95th latency percentile","hidden":false,"href":"/tests/catalog/p95-latency"},{"title":"99th latency percentile","hidden":false,"href":"/tests/catalog/p99-latency"},{"title":"Predictive power score (PPS)","hidden":false,"href":"/tests/catalog/pp-score-value-validation"},{"title":"Precision","hidden":false,"href":"/tests/catalog/precision"},{"title":"Quasi-constant features","hidden":false,"href":"/tests/catalog/quasi-constant-feature"},{"title":"Quasi-constant feature count","hidden":false,"href":"/tests/catalog/quasi-constant-feature-count"},{"title":"Quasi-exact match","hidden":false,"href":"/tests/catalog/quasi-exact-match"},{"title":"R-squared","hidden":false,"href":"/tests/catalog/r2"},{"title":"Recall","hidden":false,"href":"/tests/catalog/recall"},{"title":"Recommends competitor","hidden":false,"href":"/tests/catalog/recommends-competitor"},{"title":"Root mean squared error (RMSE)","hidden":false,"href":"/tests/catalog/rmse"},{"title":"ROC AUC","hidden":false,"href":"/tests/catalog/roc-auc"},{"title":"Number of rows","hidden":false,"href":"/tests/catalog/row-count"},{"title":"Semantic similarity","hidden":false,"href":"/tests/catalog/semantic-similarity"},{"title":"Sentence length","hidden":false,"href":"/tests/catalog/sentence-length"},{"title":"Session coherence","hidden":false,"href":"/tests/catalog/session-coherence"},{"title":"Session context retention","hidden":false,"href":"/tests/catalog/session-context-retention"},{"title":"Session conversation completeness","hidden":false,"href":"/tests/catalog/session-conversation-completeness"},{"title":"Session cost","hidden":false,"href":"/tests/catalog/session-cost"},{"title":"Session duration","hidden":false,"href":"/tests/catalog/session-duration"},{"title":"Session goal achievement","hidden":false,"href":"/tests/catalog/session-goal-achievement"},{"title":"Session guideline adherence","hidden":false,"href":"/tests/catalog/session-guideline-adherence"},{"title":"Session latency","hidden":false,"href":"/tests/catalog/session-latency"},{"title":"Session record count","hidden":false,"href":"/tests/catalog/session-record-count"},{"title":"Session role adherence","hidden":false,"href":"/tests/catalog/session-role-adherence"},{"title":"Session task progression","hidden":false,"href":"/tests/catalog/session-task-progression"},{"title":"Session token count","hidden":false,"href":"/tests/catalog/session-token-count"},{"title":"Session turn relevancy","hidden":false,"href":"/tests/catalog/session-turn-relevancy"},{"title":"Size ratio","hidden":false,"href":"/tests/catalog/size-ratio"},{"title":"Special characters ratio","hidden":false,"href":"/tests/catalog/special-characters-ratio"},{"title":"SQL query","hidden":false,"href":"/tests/catalog/sql-query"},{"title":"SQL query return rows","hidden":false,"href":"/tests/catalog/sql-query-return-rows"},{"title":"String validation","hidden":false,"href":"/tests/catalog/string-validation"},{"title":"Total cost","hidden":false,"href":"/tests/catalog/total-cost"},{"title":"Total tokens","hidden":false,"href":"/tests/catalog/total-tokens"},{"title":"Toxicity","hidden":false,"href":"/tests/catalog/toxicity"},{"title":"Training-validation leakage","hidden":false,"href":"/tests/catalog/train-val-leakage-count"},{"title":"Unauthorized tool calls","hidden":false,"href":"/tests/catalog/unauthorized-tool-calls"}]},{"title":"Tests configuration","hidden":false,"icon":"settings-2","href":"/tests/test-configuration"},{"title":"Manage tests","icon":"list-todo","href":"/tests/manage-tests"},{"title":"Semantic search filters","icon":"text-search","href":"/tests/semantic-search-filters"},{"title":"Custom metrics","icon":"pencil-line","href":"/tests/custom-metrics"}]},{"group":"Gateway","pages":[{"title":"Overview","icon":"route","href":"/gateway/overview"},{"group":"Set up \u0026 connect","icon":"plug","pages":[{"title":"Set up the gateway","href":"/gateway/set-up-the-gateway"},{"title":"Make your first request","href":"/gateway/make-your-first-request"}]},{"group":"Manage API keys","icon":"key-round","pages":[{"title":"Create API keys","href":"/gateway/api-keys"},{"title":"Assign groups","href":"/gateway/groups"},{"title":"Send invites","href":"/gateway/invites"}]},{"group":"Budgets \u0026 usage","icon":"wallet","pages":[{"title":"Set usage limits","href":"/gateway/budgets-and-limits"},{"title":"Track usage","href":"/gateway/usage-and-cost"}]},{"title":"Guardrails","icon":"shield-alert","href":"/gateway/guardrails"},{"title":"Model access","icon":"boxes","href":"/gateway/model-access"},{"title":"Observability","icon":"activity","href":"/gateway/observability"},{"title":"Errors","icon":"circle-alert","href":"/gateway/errors"},{"group":"Routing","icon":"waypoints","pages":[{"title":"Connect providers","href":"/gateway/connect-providers"},{"title":"Route requests","href":"/gateway/route-requests"},{"title":"Use any model from any SDK","href":"/gateway/use-any-model"}]}]},{"group":"Data quality monitoring","pages":[{"title":"Overview","icon":"database-zap","href":"/data-quality-monitoring/overview"},{"group":"Integrate","icon":"user-cog","pages":[{"title":"Connect a data source","hidden":false,"href":"/data-quality-monitoring/connect-data-source"}]},{"group":"Concepts","icon":"book-open","pages":[{"title":"Anomaly detection","href":"/data-quality-monitoring/anomaly-detection"}]}]},{"group":"Administration","pages":[{"title":"Security","icon":"lock","href":"/security"},{"title":"Data regions","icon":"globe","href":"/security/data-residency"},{"title":"Roles and permissions","icon":"shield-check","href":"/security/roles-and-permissions"},{"title":"SAML SSO Authentication","icon":"scan-face","href":"/security/saml-sso"},{"title":"Multi-factor Authentication","icon":"shield-check","href":"/security/multi-factor-authentication"},{"title":"Access groups","icon":"users","href":"/security/access-groups"},{"title":"Environment Variables","icon":"hexagon","href":"/security/environment-variables"},{"title":"Data retention","icon":"clock","href":"/workspace-and-projects/data-retention"}]},{"group":"Notifications","pages":[{"title":"Overview","icon":"bell","href":"/notifications/overview"},{"title":"In-app notifications","icon":"inbox","href":"/notifications/in-app"},{"title":"Email notifications","icon":"mail","href":"/notifications/email"},{"title":"Slack notifications","icon":"message-square","href":"/notifications/slack"},{"group":"Webhooks","icon":"webhook","pages":[{"title":"Overview","href":"/security/webhooks/overview"},{"title":"Manage webhooks","href":"/security/webhooks/manage-webhooks"},{"title":"Events and payloads","href":"/security/webhooks/events"},{"title":"Verify signatures","href":"/security/webhooks/verify-signatures"}]}]},{"group":"Other resources","pages":[{"title":"Glossary","icon":"case-sensitive","href":"/glossary"},{"title":"Openlayer MCP","icon":"audio-waveform","href":"/openlayer-mcp"},{"title":"Openlayer Agent Skills","icon":"wand-sparkles","href":"/openlayer-skills"},{"group":"Code examples","icon":"code","pages":[{"title":"Templates","href":"/examples/templates"},{"title":"Monitoring","href":"/examples/monitoring"}]}]}]},{"tab":"Integrations","pages":[{"title":"Integrations","href":"/integrations/overview"}]},{"tab":"Reference","pages":[{"title":"Reference","href":"/api-reference/introduction"}]}]},"basePath":"","title":"Log context for RAG systems - Openlayer","buildId":"dpl_4RHMRqtvdHvKgaEfTTjFqjzja3B6","deploymentId":"dpl_4RHMRqtvdHvKgaEfTTjFqjzja3B6","dynamics":[],"chunks":[]}