feat: add find_context_attributions() intrinsic function#679
Open
dennislwei wants to merge 18 commits intogenerative-computing:mainfrom
Open
feat: add find_context_attributions() intrinsic function#679dennislwei wants to merge 18 commits intogenerative-computing:mainfrom
find_context_attributions() intrinsic function#679dennislwei wants to merge 18 commits intogenerative-computing:mainfrom
Conversation
Wire up the uncertainty intrinsic from ibm-granite/granite-lib-core-r1.0 with a high-level check_certainty() API. The intrinsic evaluates model confidence in its response given a user question and assistant answer. - Add check_certainty(context, backend) in core.py - Extract shared call_intrinsic() helper into _util.py - Update catalog to point uncertainty at granite-lib-core-r1.0 - Add test, example, and README entry Co-Authored-By: ink-pad <inkit.padhi@gmail.com>
Co-Authored-By: ink-pad <inkit.padhi@gmail.com>
Drop the underscore prefix and alias — use call_intrinsic consistently across _util.py, rag.py, core.py, and test_rag.py. Co-Authored-By: ink-pad <inkit.padhi@gmail.com>
…hared index - Add `index` parameter to `mark_sentence_boundaries()` to allow callers to continue numbering across multiple calls; return the next available index - Add `all_but_last_message` as a valid `sentence_boundaries` key - Extend `_mark_sentence_boundaries()` to tag prior conversation turns when `all_but_last_message` is configured, using a shared running index with documents so that each context sentence has a globally unique tag Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Dennis Wei <dwei@us.ibm.com>
… decoding - Accept `source: str | list[str]` to allow a single DecodeSentences rule to decode sentences from multiple locations in one pass - Add `all_but_last_message` as a valid source, decoding prior conversation turns with a running sentence index shared across all sources - Add optional `message_index` output field that records which conversation turn each attributed sentence came from Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Dennis Wei <dwei@us.ibm.com>
- Update _CORE_REPO to "ibm-granite/granitelib-core-r1.0" - Add context-attribution intrinsic pointing to _CORE_REPO Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Dennis Wei <dwei@us.ibm.com>
- Add input/test_canned_input/test_canned_output/expected_result JSON test data files - Add YamlJsonCombo entry for context-attribution pointing to ibm-granite/granitelib-core-r1.0 - Exclude context-attribution from Ollama inference tests via _NO_OLLAMA_ADAPTER since an Ollama LoRA adapter is not yet available on the HF Hub Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Dennis Wei <dwei@us.ibm.com>
The model consistently produces {"r": 1, "c": [2, 0, 1, 19, 3]} with the
mellea codebase, yielding 7 attribution records rather than the 12 produced
on the granite-common side. Update the expected output accordingly.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Dennis Wei <dwei@us.ibm.com>
…nd _util.py Merges the feat/uq branch from mnagired/mellea which: - Extracts shared call_intrinsic() helper into _util.py - Adds check_certainty() and requirement_check() functions in core.py - Adds uncertainty and requirement_check test data Conflict resolutions: - catalog.py: keep _CORE_REPO="ibm-granite/granitelib-core-r1.0" from feat/context-attribution; drop _CORE_R1_REPO added by feat/uq - rag.py: take feat/uq refactor (drop inlined _call_intrinsic, import call_intrinsic from _util) - README.md: keep IntrinsicAdapter name; take granite-4.0-micro model update - _util.py: update GraniteCommonAdapter → IntrinsicAdapter Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Dennis Wei <dwei@us.ibm.com>
Add find_context_attributions() to core.py since the context-attribution adapter lives in the ibm-granite/granitelib-core-r1.0 repo, but modelled after find_citations() in rag.py. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Dennis Wei <dwei@us.ibm.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Dennis Wei <dwei@us.ibm.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Dennis Wei <dwei@us.ibm.com>
Conflict resolution in catalog.py: keep _CORE_REPO = "ibm-granite/rag-intrinsics-lib" for now pending full migration away from it; add _CORE_R1_REPO = "ibm-granite/granitelib-core-r1.0" for core intrinsics (context-attribution, requirement-check, uncertainty). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Dennis Wei <dwei@us.ibm.com>
Also adopt requirement-check (hyphen) intrinsic name from origin/main. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Dennis Wei <dwei@us.ibm.com>
Contributor
|
The PR description has been updated. Please fill out the template for your PR to be reviewed. |
Merge ProtectionsYour pull request matches the following merge protections and will not be merged until they are valid. 🟢 Enforce conventional commitWonderful, this rule succeeded.Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Component PR
Description
find_context_attributions()intrinsic function #677Adds
find_context_attributions()tomellea/stdlib/components/intrinsic/core.pyas a high-level API for the context-attribution intrinsic. The function finds context sentences (in prior conversation messages and RAG documents) that were most important to the LLM in generating each response sentence.find_context_attributions()is placed incore.pysince the intrinsic lives in theibm-granite/granitelib-core-r1.0repository. That said,find_context_attributions()follows a similar pattern asfind_citations()inmellea/stdlib/components/intrinsic/rag.py.Dependency: This PR depends on #661 and should be merged after that PR.
Changes:
mellea/stdlib/components/intrinsic/core.py: addsfind_context_attributions()mellea/backends/adapters/catalog.py: adds context-attribution catalog entry pointing toibm-granite/granitelib-core-r1.0docs/examples/intrinsics/context_attribution.py: usage exampletest/stdlib/components/intrinsic/test_core.py: addstest_find_context_attributionswith test dataImplementation Checklist
Protocol Compliance
parts()returns list of constituent parts (Components or CBlocks)format_for_llm()returns TemplateRepresentation or string_parse(computed: ModelOutputThunk)parses model output correctly into the specified Component return typeContent Blocks
Integration
mellea/stdlib/components/__init__.pyor, if you are adding a library of components, from your sub-modulefind_context_attributions()accessible viamellea.stdlib.components.intrinsic.coreTesting
tests/components/test_find_context_attributionsadded totest/stdlib/components/intrinsic/test_core.pywith input/output test data