Skip to main content

agrag.retrieval.tracing.retrieval_span

retrieval_span(tracer:Tracer | None, name:str, *, query:str, filters:SearchFilters | None, attributes:dict[str, Any] | None = None) -> Iterator[Span]

Open a RETRIEVER span that records the query and the scope.

Use it for retriever spans and for root spans that return SearchResults. The caller calls record_results on the yielded span before it exits.

Parameters:

  • tracer (Tracer | None) – The caller's tracer, or None for a no-op tracer.
  • name (str) – The span name, in the agrag.retrieval.* namespace.
  • query (str) – The natural-language query, or the seed's text.
  • filters (SearchFilters | None) – The scope the wrapped call runs under, always recorded.
  • attributes (dict[str, Any] | None) – Extra cheap attributes known before the call starts.

Yields:

  • Span – The open span, for record_results and any later attributes.