Skip to content

feat: citation requirement#725

Open
akihikokuroda wants to merge 9 commits intogenerative-computing:mainfrom
akihikokuroda:citation
Open

feat: citation requirement#725
akihikokuroda wants to merge 9 commits intogenerative-computing:mainfrom
akihikokuroda:citation

Conversation

@akihikokuroda
Copy link
Copy Markdown
Member

@akihikokuroda akihikokuroda commented Mar 23, 2026

Misc PR

Type of PR

  • Bug Fix
  • New Feature
  • Documentation
  • Other

Description

Testing

  • Tests added to the respective file if code was changed
  • New code has 100% coverage if code as added
  • Ensure existing tests and github automation passes (a maintainer will kick off the github automation when the rest of the PR is populated)

@akihikokuroda akihikokuroda requested a review from a team as a code owner March 23, 2026 20:06
@github-actions
Copy link
Copy Markdown
Contributor

The PR description has been updated. Please fill out the template for your PR to be reviewed.

@mergify
Copy link
Copy Markdown

mergify bot commented Mar 23, 2026

Merge Protections

Your pull request matches the following merge protections and will not be merged until they are valid.

🟢 Enforce conventional commit

Wonderful, this rule succeeded.

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert|release)(?:\(.+\))?:

@akihikokuroda akihikokuroda marked this pull request as draft March 23, 2026 20:34
@akihikokuroda akihikokuroda marked this pull request as draft March 23, 2026 20:34
@akihikokuroda akihikokuroda marked this pull request as ready for review March 23, 2026 21:50
Copy link
Copy Markdown
Collaborator

@frreiss frreiss left a comment

Choose a reason for hiding this comment

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

This needs some work. The fundamental calculation does not appear to be valid, and there are a number of puzzling API design decisions.


# Use constructor documents if provided, otherwise get from message
if self.documents is not None:
documents = self.documents
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Checking against different set of documents than those used to generate the last message is outside the target domain of the Citations intrinsic. Have you done anything to validate the assumption that such a trick would work?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This implementation is based on the current example and find_citations implementation below
https://github.com/generative-computing/mellea/blob/main/docs/examples/intrinsics/citations.py

all_messages = ctx.as_list()
if len(all_messages) > 1:
# Rebuild context without last message
from ..context import ChatContext
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why is this import not at the top of the file?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's to avoid circular dependencies

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The fact that you're seeing a circular dependency here is concerning. The only imports at the top of this file are:

from ...backends.adapters import AdapterMixin
from ...core import Backend, Context, Requirement, ValidationResult
from ..components import Document, Message

An import of mellea.stdlib.context.ChatContext ought to be compatible with these imports. What is the root cause of the dependency cycle when that dependency is added to this file?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, it is right. After looking at them again, there are no cycle dependency for ChatContext. I'll move it at top. Thanks!

citation["response_end"] - citation["response_begin"]
for citation in citations
)
coverage_ratio = cited_chars / total_chars
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Checking a ratio of characters is not in line with the original requirement in #503: "requires [sic.] citations for factual claims". You should be checking the fraction of factual claims that are backed by citations.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Implemented "fraction of factual claims" and also add an option to choose between character or factual base check.

reason += f"\n\nCitations found ({num_citations}):"
for i, citation in enumerate(citations[:5]): # Show first 5
response_text = citation["response_text"].strip()
doc_id = citation.get("citation_doc_id", "unknown")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why are you passing default values to get() here and on the next line?

@pytest.mark.requires_heavy_ram
async def test_citation_requirement_basic():
"""Test basic citation requirement functionality."""
backend = LocalHFBackend(model_id="ibm-granite/granite-4.0-micro")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Every test in this file loads the base model. Use a fixture instead.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There are both tests, accessing model and using mock. There are test markers that make selectable execution such as @pytest.mark.huggingface.

@pytest.mark.llm
@pytest.mark.requires_heavy_ram
async def test_citation_requirement_threshold_boundary():
"""Test citation requirement at exact threshold boundary."""
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Test case does not do what comment says it does. You would need to construct an input that produces the exact target threshold boundary, probably by mocking the citation intrinsic, to do what this comment says.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks! I'll fix it.

@frreiss
Copy link
Copy Markdown
Collaborator

frreiss commented Mar 24, 2026

FYI @yannisk2

@akihikokuroda
Copy link
Copy Markdown
Member Author

@frreiss Thanks for review. I addressed all of your comments so far.

@akihikokuroda akihikokuroda requested a review from frreiss March 24, 2026 16:37
@akihikokuroda
Copy link
Copy Markdown
Member Author

akihikokuroda commented Mar 24, 2026

@frreiss I missed one. I'll work on it.
It's done now.

@akihikokuroda akihikokuroda force-pushed the citation branch 2 times, most recently from 113ae32 to 0f47f16 Compare March 24, 2026 20:20
@psschwei psschwei closed this Mar 24, 2026
@psschwei psschwei reopened this Mar 24, 2026
Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
@github-actions github-actions bot added the enhancement New feature or request label Mar 24, 2026
Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hallucination Detection Requirements

3 participants