A small library to chunk large files into smaller arrays that can be used for generating RAG embeddings
Project description
chunking4rag
For implementing a good RAG framework, we need 3 steps:
- Data Ingestion/ Parsing
- Chunking
- Embedding/ Vectorization
Data Ingestion is a important steps where we extract data from a document. Aa document can be available in various formats like text, pdf, excel, csv or even Images. The data_extraction folder contains classes to extract data from different types of documents.
Chunking is the process of breaking up a document into smaller chunks. The chunking methods are implemented in the chunkingmethods folder.
The strategies discussed in this repo are:
Embedding is the process of converting text into vectors. The embedding methods are implemented in the embeddingmethods folder.
To use the library
The library is quite simple to use. Below example uses sentence chunking by extraction from text data
from data_extraction.document_parser import DocumentParser
from chunkingmethods.sentence_chunking import SentenceChunking
from chunkingdatamodel.chunking_model import ChunkingInput
text_content = "<html><body><p>Sample text content. This is a test. It has multiple sentences. It also has some punctuation.</p></body></html>"
text_document = DocumentParser(doc_type={"kind":"HTMLDocument"}).doc_type
content = text_document.get_content(text_content).pages[0].textual_content
data = ChunkingInput(text=content)
sentence_chunking = SentenceChunking(data)
chunks = sentence_chunking.chunk()
print(chunks)
# for pdf document data extraction use the following
pdf_document = DocumentParser(doc_type={"kind":"PDFDocument"}).doc_type
with open("test.pdf", "rb") as f:
extracted_content = pdf_document.get_content(f.read()).pages[0].textual_content
print(extracted_content)
To install this library
Run the following command
pip install chunking4rag
To start with contribution to the project
-
Clone the repository using git
-
Create a virtual environment using uv
uv create chunking4rag
- Activate the virtual environment
source .venv/bin/activate
- Install the dependencies by running
uv install -r requirements.txt
- Run tests to make sure everything is working fine
python chuking_tests.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file chunking4rag-0.0.5.tar.gz.
File metadata
- Download URL: chunking4rag-0.0.5.tar.gz
- Upload date:
- Size: 12.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf527221cc1d473fc331e4d7e0d969a5851d4061c0db7cab03c02782391ba5f6
|
|
| MD5 |
01c427d1df9cdc435509bf07cd967bae
|
|
| BLAKE2b-256 |
73c66b7ee8c00a30134dfa33181f9627556a3d670aa1aa67877bf98de8f393af
|
Provenance
The following attestation bundles were made for chunking4rag-0.0.5.tar.gz:
Publisher:
python-publish.yml on harpreetset1/chunking4rag
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
chunking4rag-0.0.5.tar.gz -
Subject digest:
bf527221cc1d473fc331e4d7e0d969a5851d4061c0db7cab03c02782391ba5f6 - Sigstore transparency entry: 181143730
- Sigstore integration time:
-
Permalink:
harpreetset1/chunking4rag@acd11c6e9fa455c62abf9c825edb42154ef81454 -
Branch / Tag:
refs/tags/0.0.5 - Owner: https://github.com/harpreetset1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@acd11c6e9fa455c62abf9c825edb42154ef81454 -
Trigger Event:
release
-
Statement type:
File details
Details for the file chunking4rag-0.0.5-py3-none-any.whl.
File metadata
- Download URL: chunking4rag-0.0.5-py3-none-any.whl
- Upload date:
- Size: 16.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca7c43257ac39ea54467fb8f19dde7afe0a505c8eebc44b71e4fc107bce1d38d
|
|
| MD5 |
9138c77a55c07c0a012226836c39c3af
|
|
| BLAKE2b-256 |
2bf8bbbcb5b5f9d03b8637ba49f8a1484fd618b1f265d1092e48704828d5f7e4
|
Provenance
The following attestation bundles were made for chunking4rag-0.0.5-py3-none-any.whl:
Publisher:
python-publish.yml on harpreetset1/chunking4rag
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
chunking4rag-0.0.5-py3-none-any.whl -
Subject digest:
ca7c43257ac39ea54467fb8f19dde7afe0a505c8eebc44b71e4fc107bce1d38d - Sigstore transparency entry: 181143735
- Sigstore integration time:
-
Permalink:
harpreetset1/chunking4rag@acd11c6e9fa455c62abf9c825edb42154ef81454 -
Branch / Tag:
refs/tags/0.0.5 - Owner: https://github.com/harpreetset1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@acd11c6e9fa455c62abf9c825edb42154ef81454 -
Trigger Event:
release
-
Statement type: