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

Add support for overlap between paragraphs when using TextChunker to split text #1206

Merged

Conversation

MonsterCoder
Copy link
Contributor

@MonsterCoder MonsterCoder commented May 24, 2023

Motivation and Context

When splitting large text into paragraphs for embedding, it is common to have overlap between chuncks to keep semantic context. This pattern can be used to improve semantic search quality

Description

  1. Added an overlapToken parameter to TextChuncker.SplitPlainTextParagraphs and TextChuncker.SplitMarkdownParagraphs functions. Allow max number of overlapToken tokens to be overlapped between neibouring paragraphs.
  2. Refactoring some functions. less for loop, less side-effects

Contribution Checklist

Sorry, something went wrong.

@github-actions github-actions bot added .NET Issue or Pull requests regarding .NET code kernel Issues or pull requests impacting the core kernel kernel.core labels May 24, 2023
@MonsterCoder
Copy link
Contributor Author

@microsoft-github-policy-service agree

@MonsterCoder MonsterCoder changed the title Enhancement - add overlap between paragraphs when using TextChunker to split text add overlap between paragraphs when using TextChunker to split text May 24, 2023
@MonsterCoder MonsterCoder changed the title add overlap between paragraphs when using TextChunker to split text Add support for overlap between paragraphs when using TextChunker to split text May 25, 2023
Copy link

@awakeningbyte awakeningbyte left a comment

Choose a reason for hiding this comment

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

looks good

@MonsterCoder MonsterCoder force-pushed the add_overlap_to_text_chunker branch from bca0e94 to 367cb16 Compare June 8, 2023 01:26
Copy link
Member

@lemillermicrosoft lemillermicrosoft left a comment

Choose a reason for hiding this comment

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

Thanks for the PR (and sorry for the delay), overall LGTM. A few formatting and spelling comments.

MonsterCoder and others added 3 commits June 8, 2023 16:18
Co-authored-by: Lee Miller <lemiller@microsoft.com>
Co-authored-by: Lee Miller <lemiller@microsoft.com>
Co-authored-by: Lee Miller <lemiller@microsoft.com>
@lemillermicrosoft lemillermicrosoft added PR: ready for review All feedback addressed, ready for reviews PR: ready to merge PR has been approved by all reviewers, and is ready to merge. labels Jun 9, 2023
@lemillermicrosoft lemillermicrosoft merged commit 49d79d9 into microsoft:main Jun 15, 2023
@lemillermicrosoft lemillermicrosoft added this to the Sprint 33 milestone Jun 20, 2023
shawncal pushed a commit to shawncal/semantic-kernel that referenced this pull request Jul 6, 2023
…split text (microsoft#1206)

### Motivation and Context
When splitting large text into paragraphs for embedding, it is common to
have overlap between chuncks to keep semantic context. This pattern can
be used to improve semantic search quality
### Description
1. Added an `overlapToken` parameter to
`TextChuncker.SplitPlainTextParagraphs` and
`TextChuncker.SplitMarkdownParagraphs` functions. Allow max number of
`overlapToken` tokens to be overlapped between neibouring paragraphs.
2. Refactoring some functions. less for loop, less side-effects

### Contribution Checklist
<!-- Before submitting this PR, please make sure: -->
- [x] The code builds clean without any errors or warnings
- [x] The PR follows SK Contribution Guidelines
(https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
- [x] The code follows the .NET coding conventions
(https://learn.microsoft.com/dotnet/csharp/fundamentals/coding-style/coding-conventions)
verified with `dotnet format`
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄

---------

Co-authored-by: Lee Miller <lemiller@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kernel Issues or pull requests impacting the core kernel .NET Issue or Pull requests regarding .NET code PR: ready for review All feedback addressed, ready for reviews PR: ready to merge PR has been approved by all reviewers, and is ready to merge.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants