Skip to content

Commit

Permalink
fix: correct max highlight range (#936)
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixFehse authored Jun 27, 2024
1 parent 8c0b396 commit 7d80685
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
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

0 comments on commit 7d80685

Please sign in to comment.