-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring: merge Fragment into Chunk
- Loading branch information
Showing
23 changed files
with
706 additions
and
638 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
50 changes: 50 additions & 0 deletions
50
extensions/Chunkers/Chunkers.UnitTests/MarkDownChunkerManualTest.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using System.Diagnostics; | ||
using Microsoft.KernelMemory.AI; | ||
using Microsoft.KernelMemory.Chunkers; | ||
using Microsoft.KM.TestHelpers; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Microsoft.Chunkers.UnitTests; | ||
|
||
public class MarkDownChunkerManualTest(ITestOutputHelper output) : BaseUnitTestCase(output) | ||
{ | ||
[Fact] | ||
[Trait("Category", "UnitTest")] | ||
[Trait("Category", "Chunking")] | ||
[Trait("Category", "Manual")] | ||
public void ItSplitsMarkdownInASensibleWay() | ||
{ | ||
// Arrange | ||
string text = File.ReadAllText("doc2.md"); | ||
text = $"{text}{text}"; | ||
|
||
// Act | ||
var w = new Stopwatch(); | ||
w.Start(); | ||
var chunks = new MarkDownChunker(new CL100KTokenizer()).Split(text, new MarkDownChunkerOptions { MaxTokensPerChunk = 600, Overlap = 60 }); | ||
w.Stop(); | ||
|
||
Console.WriteLine($"Text length: {text.Length:N0} chars"); | ||
Console.WriteLine($"Chunks: {chunks.Count}"); | ||
Console.WriteLine($"Time: {w.ElapsedMilliseconds:N0} ms"); | ||
|
||
// Assert | ||
Assert.NotEmpty(chunks); | ||
DebugChunks(chunks, new CL100KTokenizer()); | ||
} | ||
|
||
private static void DebugChunks(IEnumerable<string> chunks, ITextTokenizer tokenizer) | ||
{ | ||
var list = chunks.ToList(); | ||
|
||
for (int index = 0; index < list.Count; index++) | ||
{ | ||
Console.WriteLine($"************************* {index}: [{tokenizer.CountTokens(list[index])} tokens] *****************************************"); | ||
Console.WriteLine(list[index]); | ||
Console.WriteLine("***********************************************************************************"); | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.