Spaces:
Sleeping
Sleeping
Download pipeline/chunking/fixed_chunker.py from samithcs/RAG_Book_QA_System: direct link, hf CLI and curl.
- Browser
- Download file 657 Bytes
-
https://huggingface.co/spaces/samithcs/RAG_Book_QA_System/resolve/main/pipeline/chunking/fixed_chunker.py
- Command line
-
hf download hf://spaces/samithcs/RAG_Book_QA_System/pipeline/chunking/fixed_chunker.py
-
curl -L -o fixed_chunker.py https://huggingface.co/spaces/samithcs/RAG_Book_QA_System/resolve/main/pipeline/chunking/fixed_chunker.py
657 Bytes
| from typing import List, Dict | |
| from .splitter_base import SplitterBase | |
| class FixedChunker(SplitterBase): | |
| def chunk(self, text: str, chunk_size: int, overlap: int) -> List[Dict]: | |
| chunks = [] | |
| idx = 0 | |
| while idx < len(text): | |
| end = min(idx + chunk_size, len(text)) | |
| chunk_text = text[idx:end] | |
| chunks.append({ | |
| "text": chunk_text, | |
| "start": idx, | |
| "end": end, | |
| "meta": {"source": "fixed"} | |
| }) | |
| if end == len(text): | |
| break | |
| idx += chunk_size - overlap | |
| return chunks | |