feat(mistralai): surface citation metadata from chat responses#37008
feat(mistralai): surface citation metadata from chat responses#37008JulienRabault wants to merge 1 commit into
Conversation
This comment has been minimized.
This comment has been minimized.
f0f0bd7 to
c779973
Compare
ccurme (ccurme)
left a comment
There was a problem hiding this comment.
The ideal format for citations is:
- Mistral
referenceblocks in.content(untyped) - add translation to and from the standard langchain TextContentBlock in langchain_mistralai/_compat.py. This will translate the reference blocks into a text content block with an Annotation.
If it's possible to do this in a non-breaking way (e.g., if users need to opt into receiving references), this is preferred. It might be OK to make this change in a 1.2 release.
Otherwise, we can add to additional_kwargs (which is a more typical place for provider message data than response_metadata). The issue with this is we lose the sequencing of the reference in the text blocks.
|
Thanks, that makes sense. I held off on converting the Mistral I'll update the PR to preserve the native If keeping those blocks in |
|
any news ? |
Fixes #36427
Changes
referencecontent chunks intoAIMessage.response_metadata["citations"].AIMessage.contentas a string when Mistral returns typedtext/referencechunks.referencechunks from streamingdelta.contentinto chunkresponse_metadata["citations"].content_blocksconversion or citation offset calculation is added.Why
Mistral citation responses can return
contentas typed chunks, includingreferencechunks withreference_ids.Before this change,
ChatMistralAIkept only message content and dropped the citation metadata. RAG users could not map Mistral answers back to source documents through LangChain.References:
Review notes
referencechunks are stored inresponse_metadata["citations"].content_blocksannotations.AI assistance disclosure: AI tooling helped prepare this change; the submitted diff was reviewed and tested before submission.