Yes, OpenInference instrumentation libraries (such as for LangChain and LlamaIndex) automatically create spans with kind OpenInferenceSpanKindValues.RETRIEVER and store retrieved documents in the SpanAttributes.RETRIEVAL_DOCUMENTS attribute. This is confirmed by test cases and code in <https://github.com/Arize-ai/openinference/blob/main/python/instrumentation/openinference-instrumentation-llama-index/tests/openinference/instrumentation/llama_index/test_handler.py|openinference-instrumentation-llama-index> and <https://github.com/Arize-ai/openinference/blob/main/python/instrumentation/openinference-instrumentation-langchain/tests/test_instrumentor.py|openinference-instrumentation-langchain>, where retriever spans are checked for these attributes.
For custom retrievers, you can also manually set the span kind to RETRIEVER and add the RETRIEVAL_DOCUMENTS attribute using the OpenInference semantic conventions, as shown in <https://arize-ai.slack.com/archives/C04R3GXC8HK/p1715202681.227929|instrumentation examples> and <https://docs.arize.com/phoenix/tracing/how-to-tracing/instrument-python.md|manual instrumentation docs>.
Would you like more detail or a code example?
Sources:
- <https://github.com/Arize-ai/openinference/blob/main/python/instrumentation/openinference-instrumentation-llama-index/tests/openinference/instrumentation/llama_index/test_handler.py|openinference-instrumentation-llama-index/test_handler.py>
- <https://arize-ai.slack.com/archives/C04R3GXC8HK/p1715202681.227929|Slack: Instrumentation Example>
- <https://github.com/Arize-ai/openinference/blob/main/python/instrumentation/openinference-instrumentation-langchain/tests/test_instrumentor.py|openinference-instrumentation-langchain>