Skip to content

feat: Align retrieval spans with OpenTelemetry semantic conventions#145

Merged
Cirilla-zmh merged 4 commits intoalibaba:mainfrom
Cirilla-zmh:feat/retrieval-semantic-conventions
Mar 11, 2026
Merged

feat: Align retrieval spans with OpenTelemetry semantic conventions#145
Cirilla-zmh merged 4 commits intoalibaba:mainfrom
Cirilla-zmh:feat/retrieval-semantic-conventions

Conversation

@Cirilla-zmh
Copy link
Collaborator

Description

Summary

Align retrieval spans with the LoongSuite Retriever semantic convention and introduce a typed RetrievalDocument model.

Changes

Semantic Convention Updates

  • gen_ai.operation.name: retrieve_documentsretrieval
  • gen_ai.retrieval.querygen_ai.retrieval.query.text for query text
  • Span name: retrieval {gen_ai.data_source.id} when data_source_id is set
  • Add RetrieveInvocation fields: data_source_id, provider, request_model, top_k

New RetrievalDocument Dataclass

  • Typed representation with id, score, content, metadata
  • RetrieveInvocation.documents accepts List[RetrievalDocument] only
  • Instrumentation converts framework types (e.g. LangChain Document) to RetrievalDocument

Serialization (ToolDefinition-style)

  • When content capturing is NO_CONTENT: only id and score are serialized
  • When content capturing is SPAN_ONLY or SPAN_AND_EVENT: full document is serialized

LangChain Instrumentation

  • Add _documents_to_retrieval_documents() to convert LangChain Documents to RetrievalDocument
  • Update retriever spans to use the new attributes and span naming

Testing

  • Updated util-genai and langchain retriever tests
  • 14 files changed, 375 insertions, 154 deletions

Fixes #144 (issue)

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Add unit tests

Does This PR Require a Core Repo Change?

  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

Change-Id: Ic0a6f4856fbde936feb7c6e6d5e2038d1d72849a
Co-developed-by: Cursor <noreply@cursor.com>
Change-Id: I12e3db0daf66d59d180a0fb345c675b4d988f802
Co-developed-by: Cursor <noreply@cursor.com>
@Cirilla-zmh Cirilla-zmh changed the title feat: Align retrieval spans with LoongSuite semantic conventions feat: Align retrieval spans with OpenTelemetry semantic conventions Mar 11, 2026
@Cirilla-zmh Cirilla-zmh added documentation Improvements or additions to documentation enhancement New feature or request instrumentaion The instrumentation label represents issues related to instrumentation. genai The genai label represents issues related to generative AI. labels Mar 11, 2026
Change-Id: Ic1118007311a8612531c1403f0905056d8825c02
Co-developed-by: Cursor <noreply@cursor.com>
Change-Id: I4c35670d22b154d9e16003c672b0b8122b337195
Co-developed-by: Cursor <noreply@cursor.com>
@Cirilla-zmh Cirilla-zmh merged commit 33fb2d6 into alibaba:main Mar 11, 2026
86 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request genai The genai label represents issues related to generative AI. instrumentaion The instrumentation label represents issues related to instrumentation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Update loongsuite-util-genai for the latest semantic conventions of retrieval

3 participants