Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct max highlight range #936

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- `PromptTemplate.to_rich_prompt` now always returns an empty list for prompt ranges that are empty.
- `SingleChunkQa` no longer crashes if given an empty input and a specific prompt template. This did not affect users who used models provided in `core`.
- Added default values for `labels` and `metadata` for `EvaluationOverview` and `RunOverview`
- In the `MultipleChunkRetrieverQa`, text-highlight start and end points are now restricted to within the text length of the respective chunk.

### Deprecations
...
Expand Down
16 changes: 12 additions & 4 deletions src/intelligence_layer/examples/qa/multiple_chunk_retriever_qa.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,15 @@ def _combine_input_texts(
start_indices: list[int] = []
combined_text = ""
for i, chunk in enumerate(chunks):
combined_text += source_appendix.format(i=i + 1)
start_indices.append(len(combined_text))
combined_text += chunk + "\n\n"
return (TextChunk(combined_text.strip()), start_indices)

c = source_appendix.format(i=i + 1)
c += chunk + "\n\n"
c = c.strip()
if i != 0:
c = " " + c
combined_text += c
return (TextChunk(combined_text), start_indices)

@staticmethod
def _get_highlights_per_chunk(
Expand All @@ -182,7 +187,10 @@ def _get_highlights_per_chunk(
end=(
highlight.end - current_start
if isinstance(next_start, float)
else min(next_start, highlight.end - current_start)
else min(
next_start - current_start,
highlight.end - current_start,
)
),
score=highlight.score,
)
Expand Down