ARCANA References#
Parse GWDG ARCANA reference blocks from chat-completion content.
When a request is routed through GWDG SAIA’s ARCANA (RAG) gateway, the
gateway appends a verbose References: block to the assistant’s reply —
one [RREFn] <filename>.md (<distance>) line per retrieved chunk,
followed by that chunk’s body. This module turns that GWDG-specific wire
shape into structured data, leaving rendering and filename
interpretation to the caller: a filename’s meaning depends on your own
corpus, and presentation depends on your own UI, so neither belongs here.
The module is pure and dependency-free (no HTTP, no I/O), so it is safe to import into any environment — including an async server — without pulling in a transport layer.
Example:
from saia_python import parse_arcana_references
parsed = parse_arcana_references(message_content)
if parsed.matched:
print(parsed.prose) # the answer, References block removed
for ref in parsed.references: # structured citations
print(ref.n, ref.filename, ref.distance)
- class saia_python.arcana_references.ArcanaReference(n: int, filename: str, distance: float | None = None)[source]#
A single parsed ARCANA citation.
- Variables:
n (int) – The
RREFnreference number emitted by the gateway.filename (str) – The retrieved chunk’s source filename (e.g.
"onkopedia_....md"). Deriving a label or URL from it is the caller’s responsibility — it depends on your corpus.distance (float | None) – The retrieval distance score the gateway reports in parentheses, or
Noneif it could not be parsed as a float.
- class saia_python.arcana_references.ParsedReferences(matched: bool, prose: str, references: list[ArcanaReference] = <factory>, references_block: str = '')[source]#
The result of splitting assistant content around the References block.
- Variables:
matched (bool) – Whether a
References:block was found.prose (str) – The assistant content with the References block removed (the substring before the marker). Equal to the full input when
matchedisFalse. Note this still includes any trailing horizontal-rule line the gateway inserts beforeReferences:— stripping that is a rendering concern left to the caller.references (list[saia_python.arcana_references.ArcanaReference]) – Parsed, de-duplicated citations, ordered by
n.references_block (str) – The raw References block (marker to end of input), or
""whenmatchedisFalse.
- references: list[ArcanaReference]#
- saia_python.arcana_references.parse_arcana_references(content: str) ParsedReferences[source]#
Split assistant
contentinto prose and structured references.Locates the GWDG
References:marker; everything before it is prose, everything from it onward is parsed intoArcanaReferenceentries. Conservative: if no marker is present, returns the content unchanged asprosewithmatched=Falseand no references.- Parameters:
content – The assistant message content from an ARCANA-routed reply.
- Returns:
- saia_python.arcana_references.parse_reference_entries(block: str, *, dedupe: bool = True) list[ArcanaReference][source]#
Parse
[RREFn] <filename>.md (<distance>)entries fromblock.- Parameters:
block – Text containing one or more reference entry lines (typically the References block, but any text works — non-matching lines are ignored).
dedupe – When
True(default), collapse repeated filenames to a single entry keeping the lowestn(the gateway lists a filename once per retrieved chunk, so one document can appear several times); the result is ordered byn. WhenFalse, every matching entry is returned in document order.
- Returns:
A list of
ArcanaReference.
- saia_python.arcana_references.is_arcana_event(tool_call: dict) bool[source]#
Return
Trueiftool_callis a GWDGarcana.eventbeacon.GWDG ARCANA streams retrieval-lifecycle markers (
accessing/done) astool_callswhose function name starts witharcana.event. These are status signals, not real citations (the actual references are baked into the message content as[RREFn]markers), so consumers typically filter them out before rendering.