graphrag-chunking 3.0.1__tar.gz → 3.0.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (19) hide show
  1. {graphrag_chunking-3.0.1 → graphrag_chunking-3.0.3}/.gitignore +4 -0
  2. {graphrag_chunking-3.0.1 → graphrag_chunking-3.0.3}/PKG-INFO +6 -23
  3. {graphrag_chunking-3.0.1 → graphrag_chunking-3.0.3}/README.md +4 -21
  4. graphrag_chunking-3.0.3/example_notebooks/basic_sentence_example.ipynb +60 -0
  5. graphrag_chunking-3.0.3/example_notebooks/factory_helper_util_example.ipynb +77 -0
  6. graphrag_chunking-3.0.3/example_notebooks/token_chunking_example.ipynb +72 -0
  7. {graphrag_chunking-3.0.1 → graphrag_chunking-3.0.3}/pyproject.toml +2 -2
  8. {graphrag_chunking-3.0.1 → graphrag_chunking-3.0.3}/LICENSE +0 -0
  9. {graphrag_chunking-3.0.1 → graphrag_chunking-3.0.3}/graphrag_chunking/__init__.py +0 -0
  10. {graphrag_chunking-3.0.1 → graphrag_chunking-3.0.3}/graphrag_chunking/bootstrap_nltk.py +0 -0
  11. {graphrag_chunking-3.0.1 → graphrag_chunking-3.0.3}/graphrag_chunking/chunk_strategy_type.py +0 -0
  12. {graphrag_chunking-3.0.1 → graphrag_chunking-3.0.3}/graphrag_chunking/chunker.py +0 -0
  13. {graphrag_chunking-3.0.1 → graphrag_chunking-3.0.3}/graphrag_chunking/chunker_factory.py +0 -0
  14. {graphrag_chunking-3.0.1 → graphrag_chunking-3.0.3}/graphrag_chunking/chunking_config.py +0 -0
  15. {graphrag_chunking-3.0.1 → graphrag_chunking-3.0.3}/graphrag_chunking/create_chunk_results.py +0 -0
  16. {graphrag_chunking-3.0.1 → graphrag_chunking-3.0.3}/graphrag_chunking/sentence_chunker.py +0 -0
  17. {graphrag_chunking-3.0.1 → graphrag_chunking-3.0.3}/graphrag_chunking/text_chunk.py +0 -0
  18. {graphrag_chunking-3.0.1 → graphrag_chunking-3.0.3}/graphrag_chunking/token_chunker.py +0 -0
  19. {graphrag_chunking-3.0.1 → graphrag_chunking-3.0.3}/graphrag_chunking/transformers.py +0 -0
@@ -63,3 +63,7 @@ docsite/
63
63
 
64
64
  # Root build assets
65
65
  packages/*/LICENSE
66
+
67
+ # Notebooks outputs
68
+ packages/graphrag-*/example_notebooks/**/output
69
+ packages/graphrag-*/example_notebooks/**/cache
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: graphrag-chunking
3
- Version: 3.0.1
3
+ Version: 3.0.3
4
4
  Summary: Chunking utilities for GraphRAG
5
5
  Project-URL: Source, https://github.com/microsoft/graphrag
6
6
  Author: Mónica Carvajal
@@ -12,7 +12,7 @@ Classifier: Programming Language :: Python :: 3.11
12
12
  Classifier: Programming Language :: Python :: 3.12
13
13
  Classifier: Programming Language :: Python :: 3.13
14
14
  Requires-Python: <3.14,>=3.11
15
- Requires-Dist: graphrag-common==3.0.1
15
+ Requires-Dist: graphrag-common==3.0.2
16
16
  Requires-Dist: pydantic~=2.10
17
17
  Description-Content-Type: text/markdown
18
18
 
@@ -26,34 +26,17 @@ This package contains a collection of text chunkers, a core config model, and a
26
26
 
27
27
  The SentenceChunker class splits text into individual sentences by identifying sentence boundaries. It takes input text and returns a list where each element is a separate sentence, making it easy to process text at the sentence level.
28
28
 
29
- ```python
30
- chunker = SentenceChunker()
31
- chunks = chunker.chunk("This is a test. Another sentence.")
32
- print(chunks) # ["This is a test.", "Another sentence."]
33
- ```
29
+ [Open the notebook to explore the basic sentence example code](example_notebooks/basic_sentence_example.ipynb)
34
30
 
35
31
  ### Token chunking
36
32
 
37
33
  The TokenChunker splits text into fixed-size chunks based on token count rather than sentence boundaries. It uses a tokenizer to encode text into tokens, then creates chunks of a specified size with configurable overlap between chunks.
38
34
 
39
- ```python
40
- tokenizer = tiktoken.get_encoding("o200k_base")
41
- chunker = TokenChunker(size=3, overlap=0, encode=tokenizer.encode, decode=tokenizer.decode)
42
- chunks = chunker.chunk("This is a random test fragment of some text")
43
- print(chunks) # ["This is a", " random test fragment", " of some text"]
44
- ```
35
+ [Open the notebook to explore the token chunking example code](example_notebooks/token_chunking_example.ipynb)
36
+
45
37
 
46
38
  ### Using the factory via helper util
47
39
 
48
40
  The create_chunker factory function provides a configuration-driven approach to instantiate chunkers by accepting a ChunkingConfig object that specifies the chunking strategy and parameters. This allows for more flexible and maintainable code by separating chunker configuration from direct instantiation.
49
41
 
50
- ```python
51
- tokenizer = tiktoken.get_encoding("o200k_base")
52
- config = ChunkingConfig(
53
- strategy="tokens",
54
- size=3,
55
- overlap=0
56
- )
57
- chunker = create_chunker(config, tokenizer.encode, tokenizer.decode)
58
- ...
59
- ```
42
+ [Open the notebook to explore the factory helper util example code](example_notebooks/factory_helper_util_example.ipynb)
@@ -8,34 +8,17 @@ This package contains a collection of text chunkers, a core config model, and a
8
8
 
9
9
  The SentenceChunker class splits text into individual sentences by identifying sentence boundaries. It takes input text and returns a list where each element is a separate sentence, making it easy to process text at the sentence level.
10
10
 
11
- ```python
12
- chunker = SentenceChunker()
13
- chunks = chunker.chunk("This is a test. Another sentence.")
14
- print(chunks) # ["This is a test.", "Another sentence."]
15
- ```
11
+ [Open the notebook to explore the basic sentence example code](example_notebooks/basic_sentence_example.ipynb)
16
12
 
17
13
  ### Token chunking
18
14
 
19
15
  The TokenChunker splits text into fixed-size chunks based on token count rather than sentence boundaries. It uses a tokenizer to encode text into tokens, then creates chunks of a specified size with configurable overlap between chunks.
20
16
 
21
- ```python
22
- tokenizer = tiktoken.get_encoding("o200k_base")
23
- chunker = TokenChunker(size=3, overlap=0, encode=tokenizer.encode, decode=tokenizer.decode)
24
- chunks = chunker.chunk("This is a random test fragment of some text")
25
- print(chunks) # ["This is a", " random test fragment", " of some text"]
26
- ```
17
+ [Open the notebook to explore the token chunking example code](example_notebooks/token_chunking_example.ipynb)
18
+
27
19
 
28
20
  ### Using the factory via helper util
29
21
 
30
22
  The create_chunker factory function provides a configuration-driven approach to instantiate chunkers by accepting a ChunkingConfig object that specifies the chunking strategy and parameters. This allows for more flexible and maintainable code by separating chunker configuration from direct instantiation.
31
23
 
32
- ```python
33
- tokenizer = tiktoken.get_encoding("o200k_base")
34
- config = ChunkingConfig(
35
- strategy="tokens",
36
- size=3,
37
- overlap=0
38
- )
39
- chunker = create_chunker(config, tokenizer.encode, tokenizer.decode)
40
- ...
41
- ```
24
+ [Open the notebook to explore the factory helper util example code](example_notebooks/factory_helper_util_example.ipynb)
@@ -0,0 +1,60 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "id": "a91f3280",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "# Copyright (c) 2026 Microsoft Corporation.\n",
11
+ "# Licensed under the MIT License."
12
+ ]
13
+ },
14
+ {
15
+ "cell_type": "markdown",
16
+ "id": "3f76dc60",
17
+ "metadata": {},
18
+ "source": [
19
+ "## Basic sentence chunking with nltk\n",
20
+ "\n",
21
+ "The SentenceChunker class splits text into individual sentences by identifying sentence boundaries. It takes input text and returns a list where each element is a separate sentence, making it easy to process text at the sentence level."
22
+ ]
23
+ },
24
+ {
25
+ "cell_type": "code",
26
+ "execution_count": null,
27
+ "id": "4c96d3cc",
28
+ "metadata": {},
29
+ "outputs": [],
30
+ "source": [
31
+ "from graphrag_chunking.sentence_chunker import SentenceChunker\n",
32
+ "\n",
33
+ "chunker = SentenceChunker()\n",
34
+ "chunks = chunker.chunk(\"This is a test. Another sentence.\")\n",
35
+ "print(chunks) # [\"This is a test.\", \"Another sentence.\"]"
36
+ ]
37
+ }
38
+ ],
39
+ "metadata": {
40
+ "kernelspec": {
41
+ "display_name": "Python 3",
42
+ "language": "python",
43
+ "name": "python3"
44
+ },
45
+ "language_info": {
46
+ "codemirror_mode": {
47
+ "name": "ipython",
48
+ "version": 3
49
+ },
50
+ "file_extension": ".py",
51
+ "mimetype": "text/x-python",
52
+ "name": "python",
53
+ "nbconvert_exporter": "python",
54
+ "pygments_lexer": "ipython3",
55
+ "version": "3.12.9"
56
+ }
57
+ },
58
+ "nbformat": 4,
59
+ "nbformat_minor": 5
60
+ }
@@ -0,0 +1,77 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 3,
6
+ "id": "cf52b7c7",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "# Copyright (c) 2026 Microsoft Corporation.\n",
11
+ "# Licensed under the MIT License."
12
+ ]
13
+ },
14
+ {
15
+ "cell_type": "markdown",
16
+ "id": "37a05202",
17
+ "metadata": {},
18
+ "source": [
19
+ "## Using the factory via helper util example\n",
20
+ "\n",
21
+ "\n",
22
+ "The create_chunker factory function provides a configuration-driven approach to instantiate chunkers by accepting a ChunkingConfig object that specifies the chunking strategy and parameters. This allows for more flexible and maintainable code by separating chunker configuration from direct instantiation."
23
+ ]
24
+ },
25
+ {
26
+ "cell_type": "code",
27
+ "execution_count": 4,
28
+ "id": "027e9c45",
29
+ "metadata": {},
30
+ "outputs": [
31
+ {
32
+ "name": "stdout",
33
+ "output_type": "stream",
34
+ "text": [
35
+ "[TextChunk(original='This is a', text='This is a', index=0, start_char=0, end_char=8, token_count=3), TextChunk(original=' test. Another', text=' test. Another', index=1, start_char=9, end_char=22, token_count=3), TextChunk(original=' sentence. And', text=' sentence. And', index=2, start_char=23, end_char=36, token_count=3), TextChunk(original=' another one.', text=' another one.', index=3, start_char=37, end_char=49, token_count=3)]\n"
36
+ ]
37
+ }
38
+ ],
39
+ "source": [
40
+ "import tiktoken\n",
41
+ "from graphrag_chunking.chunker_factory import create_chunker\n",
42
+ "from graphrag_chunking.chunking_config import ChunkingConfig\n",
43
+ "\n",
44
+ "tokenizer = tiktoken.get_encoding(\"o200k_base\")\n",
45
+ "config = ChunkingConfig(\n",
46
+ " strategy=\"tokens\", # type: ignore\n",
47
+ " size=3,\n",
48
+ " overlap=0,\n",
49
+ ")\n",
50
+ "chunker = create_chunker(config, tokenizer.encode, tokenizer.decode)\n",
51
+ "\n",
52
+ "print(chunker.chunk(\"This is a test. Another sentence. And another one.\"))"
53
+ ]
54
+ }
55
+ ],
56
+ "metadata": {
57
+ "kernelspec": {
58
+ "display_name": "Python 3",
59
+ "language": "python",
60
+ "name": "python3"
61
+ },
62
+ "language_info": {
63
+ "codemirror_mode": {
64
+ "name": "ipython",
65
+ "version": 3
66
+ },
67
+ "file_extension": ".py",
68
+ "mimetype": "text/x-python",
69
+ "name": "python",
70
+ "nbconvert_exporter": "python",
71
+ "pygments_lexer": "ipython3",
72
+ "version": "3.12.9"
73
+ }
74
+ },
75
+ "nbformat": 4,
76
+ "nbformat_minor": 5
77
+ }
@@ -0,0 +1,72 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "41bf35b3",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "# Copyright (c) 2026 Microsoft Corporation.\n",
11
+ "# Licensed under the MIT License."
12
+ ]
13
+ },
14
+ {
15
+ "cell_type": "markdown",
16
+ "id": "0c59c030",
17
+ "metadata": {},
18
+ "source": [
19
+ "## Token chunking example\n",
20
+ "\n",
21
+ "The TokenChunker splits text into fixed-size chunks based on token count rather than sentence boundaries. It uses a tokenizer to encode text into tokens, then creates chunks of a specified size with configurable overlap between chunks."
22
+ ]
23
+ },
24
+ {
25
+ "cell_type": "code",
26
+ "execution_count": 2,
27
+ "id": "cd653d39",
28
+ "metadata": {},
29
+ "outputs": [
30
+ {
31
+ "name": "stdout",
32
+ "output_type": "stream",
33
+ "text": [
34
+ "[TextChunk(original='This is a', text='This is a', index=0, start_char=0, end_char=8, token_count=3), TextChunk(original=' random test fragment', text=' random test fragment', index=1, start_char=9, end_char=29, token_count=3), TextChunk(original=' of some text', text=' of some text', index=2, start_char=30, end_char=42, token_count=3)]\n"
35
+ ]
36
+ }
37
+ ],
38
+ "source": [
39
+ "import tiktoken\n",
40
+ "from graphrag_chunking.token_chunker import TokenChunker\n",
41
+ "\n",
42
+ "tokenizer = tiktoken.get_encoding(\"o200k_base\")\n",
43
+ "chunker = TokenChunker(\n",
44
+ " size=3, overlap=0, encode=tokenizer.encode, decode=tokenizer.decode\n",
45
+ ")\n",
46
+ "chunks = chunker.chunk(\"This is a random test fragment of some text\")\n",
47
+ "print(chunks) # [\"This is a\", \" random test fragment\", \" of some text\"]"
48
+ ]
49
+ }
50
+ ],
51
+ "metadata": {
52
+ "kernelspec": {
53
+ "display_name": "Python 3",
54
+ "language": "python",
55
+ "name": "python3"
56
+ },
57
+ "language_info": {
58
+ "codemirror_mode": {
59
+ "name": "ipython",
60
+ "version": 3
61
+ },
62
+ "file_extension": ".py",
63
+ "mimetype": "text/x-python",
64
+ "name": "python",
65
+ "nbconvert_exporter": "python",
66
+ "pygments_lexer": "ipython3",
67
+ "version": "3.12.9"
68
+ }
69
+ },
70
+ "nbformat": 4,
71
+ "nbformat_minor": 5
72
+ }
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "graphrag-chunking"
3
- version = "3.0.1"
3
+ version = "3.0.3"
4
4
  description = "Chunking utilities for GraphRAG"
5
5
  authors = [
6
6
  {name = "Alonso Guevara Fernández", email = "alonsog@microsoft.com"},
@@ -30,7 +30,7 @@ classifiers = [
30
30
  "Programming Language :: Python :: 3.13",
31
31
  ]
32
32
  dependencies = [
33
- "graphrag-common==3.0.1",
33
+ "graphrag-common==3.0.2",
34
34
  "pydantic~=2.10",
35
35
  ]
36
36