| 83 | |
| 84 | # Fixed-length word chunks |
| 85 | class FixedLengthWordChunking(ChunkingStrategy): |
| 86 | def __init__(self, chunk_size=100, **kwargs): |
| 87 | """ |
| 88 | Initialize the fixed-length word chunking strategy with the given chunk size. |
| 89 | |
| 90 | Args: |
| 91 | chunk_size (int): The size of each chunk in words. |
| 92 | """ |
| 93 | self.chunk_size = chunk_size |
| 94 | |
| 95 | def chunk(self, text: str) -> list: |
| 96 | words = text.split() |
| 97 | return [' '.join(words[i:i + self.chunk_size]) for i in range(0, len(words), self.chunk_size)] |
| 98 | |
| 99 | # Sliding window chunking |
| 100 | class SlidingWindowChunking(ChunkingStrategy): |
no outgoing calls
searching dependent graphs…