Skip to content

Conversation

@jason-raitz
Copy link
Contributor

…istory and instructions.

Copy link
Member

@anarchivist anarchivist left a comment

Choose a reason for hiding this comment

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

interesting work - i'm excited to see this proceeding.

Comment on lines 99 to 100
"start_index": str(doc.metadata.get('start_index')) if doc.metadata.get('start_index') else '',
"total_pages": str(doc.metadata.get('total_pages')) if doc.metadata.get('total_pages') else '',
Copy link
Member

Choose a reason for hiding this comment

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

is there a reason why we're returning empty strings here and not None?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the model is expecting a string

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And we don't actually need these two values. I just thought it might be helpful to the model. we could drop both if we want.

prompt = get_langfuse_prompt()
system_messages = prompt.invoke({'context': docs_context,
'question': latest_message.content})
system_messages = prompt.invoke({})
Copy link
Member

Choose a reason for hiding this comment

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

what's this doing? where is the user's question being inserted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The user's question is passed as a user message like it always is. There actually might be unrelated cleanup work for us to do with that. Right now, we're passing the user query as a user message twice (due to the summary bit) and then again as part of the system message (instruction prompt).

 - this gets cohere specific response field that includes citations for the response text
@jason-raitz jason-raitz force-pushed the AP-532_cohere_structured_query branch from 9cce4d4 to e999fa8 Compare December 19, 2025 16:28
additional_model_request_fields={"documents": documents},
additional_model_response_field_paths=["/citations"]
)
citations = response.response_metadata.get('additionalModelResponseFields').get('citations') if response.response_metadata else None
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's neat about this, is that the citations returned by cohere can be used to cite specific parts of the response message to documents that we passed above in line 145.

An example list of citations look like this:

[
  {
      "start": 184,
      "end": 229,
      "text": "admission criteria and standards of practice.",
      "document_ids": ["doc_0"]
  },
  {
      "start": 260,
      "end": 275,
      "text": "different roles",
      "document_ids": ["doc_1", "doc_2"]
  }
]

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants