Skip to content

Use shared retrieval document model across instrumentations - #775

Open
JacksonWeber wants to merge 3 commits into
open-telemetry:mainfrom
JacksonWeber:issue-743-retrieval-documents
Open

JacksonWeber wants to merge 3 commits into
open-telemetry:mainfrom
JacksonWeber:issue-743-retrieval-documents

Conversation

@JacksonWeber

@JacksonWeber JacksonWeber commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Description

Add the shared RetrievalDocument model with optional id and score fields and adopt it in DSPy, LangChain, and LlamaIndex for gen_ai.retrieval.documents.

Document text is no longer captured; unavailable IDs and scores serialize as null. Query capture, content-capture gating, SDK return values, and legacy dictionary serialization in the util remain unchanged. Includes regression tests and README updates.

Fixes #743.

Type of change

  • Breaking change to captured retrieval document content
  • This change requires a documentation update

How has this been tested?

333 targeted tests passed in an isolated Python 3.12 environment. Run python -m pytest against these files with the corresponding package/test dependencies installed:

  • util/opentelemetry-util-genai/tests/test_handler_retrieval.py — 32 passed.
  • instrumentation/opentelemetry-instrumentation-genai-dspy/tests/test_retrieve.py — 12 passed.
  • instrumentation/opentelemetry-instrumentation-genai-langchain/tests/test_retriever.py and tests/test_callback_handler.py in the same package — 278 passed.
  • instrumentation/opentelemetry-instrumentation-genai-llama-index/tests/test_retrieval.py — 11 passed.

Scoped Pyright, Ruff, formatting, rstcheck, and PyPI README rendering checks passed. Full tox gates (oldest/latest, conformance, precommit, and typecheck) were attempted but blocked during dependency setup by PyPI TLS handshake failures.

Checklist

  • Followed the style guidelines of this project
  • Changelog finalized — four fragments are included; their +retrieval-documents filenames still need to be renamed to 775
  • Unit tests added
  • Documentation updated

Assisted-by: GPT-6 Astra

Add RetrievalDocument with optional id and score fields and adopt it in DSPy, LangChain, and LlamaIndex. Stop capturing document text while preserving query capture and legacy dictionary serialization. Cover the behavior with regression tests, README updates, and changelog fragments.

Refs open-telemetry#743

Assisted-by: GPT-6 Astra

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Sep 23, 2026

Copy link
Copy Markdown

Pull request dashboard status

Waiting on the author · refreshed 2026-09-23 14:13 UTC

Respond to 1 review item (e.g. link a commit, explain why not, ask a follow-up):

  • Inline threads: 1
Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Should this be with reviewers? Comment /dashboard route:reviewers to route it to them.
  • Anything wrong — including the routing? Report it with what you expected; it helps us improve the dashboard.

Assisted-by: GPT-6 Astra

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

LlamaIndex extraction needs exception guarding and non-finite score normalization.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity · 1 Medium severity

Open (2)
What changed in this PR

Introduces a shared RetrievalDocument model across DSPy, LangChain, and LlamaIndex while stopping document-text capture.

Changes:

  • Adds optional IDs and scores with legacy serialization support.
  • Updates instrumentation, tests, documentation, and changelogs.
  • Preserves query capture.
File Description
util/​opentelemetry-util-genai/​tests/​test_handler_retrieval.py Tests typed and legacy document serialization.
util/​opentelemetry-util-genai/​src/​opentelemetry/​util/​genai/​types.py Adds RetrievalDocument.
util/​opentelemetry-util-genai/​src/​opentelemetry/​util/​genai/​_retrieval_invocation.py Supports typed and legacy documents.
util/​opentelemetry-util-genai/​README.rst Documents the shared model.
util/​opentelemetry-util-genai/​.changelog/​+retrieval-documents.added Records the utility change.
instrumentation/​opentelemetry-instrumentation-genai-llama-index/​tests/​test_retrieval.py Tests ID and score extraction.
instrumentation/​opentelemetry-instrumentation-genai-llama-index/​src/​opentelemetry/​instrumentation/​genai/​llama_index/​_handler.py Emits typed retrieval documents.
instrumentation/​opentelemetry-instrumentation-genai-llama-index/​README.rst Documents retrieval capture changes.
instrumentation/​opentelemetry-instrumentation-genai-llama-index/​.changelog/​+retrieval-documents.changed Records instrumentation changes.
instrumentation/​opentelemetry-instrumentation-genai-langchain/​tests/​test_retriever.py Updates retrieval assertions.
instrumentation/​opentelemetry-instrumentation-genai-langchain/​tests/​test_callback_handler.py Tests typed document conversion.
instrumentation/​opentelemetry-instrumentation-genai-langchain/​src/​opentelemetry/​instrumentation/​genai/​langchain/​callback_handler.py Converts documents to RetrievalDocument.
instrumentation/​opentelemetry-instrumentation-genai-langchain/​README.rst Documents ID and score-only capture.
instrumentation/​opentelemetry-instrumentation-genai-langchain/​.changelog/​+retrieval-documents.changed Records instrumentation changes.
instrumentation/​opentelemetry-instrumentation-genai-dspy/​tests/​test_retrieve.py Tests passage-count and content suppression behavior.
instrumentation/​opentelemetry-instrumentation-genai-dspy/​src/​opentelemetry/​instrumentation/​genai/​dspy/​patch.py Emits typed documents for text-only passages.
instrumentation/​opentelemetry-instrumentation-genai-dspy/​README.rst Documents DSPy retrieval behavior.
instrumentation/​opentelemetry-instrumentation-genai-dspy/​.changelog/​+retrieval-documents.changed Records instrumentation changes.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Assisted-by: GPT-6 Astra

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

invocation.documents = [{"content": str(psg)} for psg in passages]
# Retrieve returns passage text, without document IDs or scores.
invocation.documents = [RetrievalDocument() for _ in passages]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunate we end up with empty docs here, but that's what semconv does right now. Created open-telemetry/semantic-conventions-genai#537 to track, let's follow up once it's resolved in some way.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Use retrieved doc model from utils across instrumentations and clean up existing code

3 participants