-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtext_chunker.py
More file actions
33 lines (24 loc) · 1.05 KB
/
text_chunker.py
File metadata and controls
33 lines (24 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""Module containing the TextChunker class."""
from langchain_core.documents import Document
from langchain_text_splitters import RecursiveCharacterTextSplitter
from admin_api_lib.chunker.chunker import Chunker
class TextChunker(Chunker):
"""A class that chunks text documents into smaller chunks."""
def __init__(self, splitter: RecursiveCharacterTextSplitter):
# NOTE: `CharacterTextSplitter` does not take chunk_size into consideration
# See: https://github.com/langchain-ai/langchain/issues/10410#issuecomment-1712595675
# for that reason, we use the recursive splitter
self._splitter = splitter
def chunk(self, documents: list[Document]) -> list[Document]:
"""
Chunk the given documents into smaller chunks.
Parameters
----------
documents : list[Document]
The documents to be chunked.
Returns
-------
list[Document]
The list of chunked documents.
"""
return self._splitter.split_documents(documents)