RAG implementation pipeline with GPU support
Project description
Basic Usage
Create a vector store from a document and query it using semantic search.
Example
import maskyrag
identifier = maskyrag.create_vector("file/path/to/document.pdf")
# Search the vector store
for page_number, result in enumerate(
maskyrag.search_in_vector_store("What is VA?", identifier)
):
print(f"\nPage {page_number}")
print(result.page_content)
Output
Page 0
VA (Value Added) is ...
Page 1
Additional information about VA ...
API Reference
create_vector(path)
Creates a vector store from a supported document.
Parameters
| Name | Type | Description |
|---|---|---|
path |
str |
Path to the input document. |
Returns
| Type | Description |
|---|---|
| Vector Store Identifier | Searchable vector index containing document embeddings. |
search_in_vector_store(query, identifier)
Performs semantic similarity search against a vector store.
Parameters
| Name | Type | Description |
|---|---|---|
query |
str |
Natural language search query. |
identifier |
Vector Store | Previously created vector store. |
Returns
| Type | Description |
|---|---|
list[Document] |
Matching document chunks ranked by relevance. |
Supported File Types
| Type | Extensions |
|---|---|
| PDF Documents | .pdf |
| Word Documents | .docx |
| Excel Spreadsheets | .xlsx |
| PowerPoint Presentations | .pptx |
| Text Files | .txt |
| Markdown Files | .md |
| CSV Files | .csv |
Document Loader
Helps to load different document types into standard document object
load_from_file(file_object, file_extension)
Loads file from file object which is binary
Parameters
| Name | Type | Description |
|---|---|---|
file_object |
_io.BufferedReader |
File object with 'rb'. |
file_extension |
str |
File extension. |
Returns
| Type | Description |
|---|---|
| List | List of documents containing information. |
Example
from maskyrag import document_loaders
file_name = "a.pdf"
file = open(file_name, "rb")
documents = document_loaders.load_from_file(file, ".pdf")
file.close()
print(documents)
Output
[Document(metadata={'source': 'file_object', 'page': 1}, page_content='...'), ...]
load_from_file_path(file_path)
Loads file from file path
Parameters
| Name | Type | Description |
|---|---|---|
file_path |
str |
File path. |
Returns
| Type | Description |
|---|---|
| List | List of documents containing information. |
Example
from maskyrag import document_loaders
file_name = "a.pdf"
documents = document_loaders.load_from_file_path(file_name)
print(documents)
Output
[Document(metadata={'source': 'file_object', 'page': 1}, page_content='...'), ...]
Document Splitter
Helps to split documents into chunks
get_chunks(documents, chunk_size=1000, chunk_overlap=200)
Splits the given documents object based on given chunk size
Parameters
| Name | Type | Description |
|---|---|---|
documents |
list |
List of document objects. |
chunk_size |
int |
Maximum size of data in a single document. |
chunk_overlap |
int |
the number of characters that are shared between consecutive chunks when splitting a document. |
Returns
| Type | Description |
|---|---|
| List | List of documents containing information. |
Example
from maskyrag import document_loaders
from maskyrag import document_splitter
file_name = "a.pdf"
documents = document_loaders.load_from_file_path(file_name)
chunks = document_splitter.get_chunks(documents, chunk_size=100, chunk_overlap=10)
print(chunks)
Output
[Document(metadata={'source': 'file_object', 'page': 1}, page_content='...'), ...]
Embedding Generator
Gets embedding vector model
list_embeddings_model()
Lists all Embeddings Models
Returns
| Type | Description |
|---|---|
| List | List of known model names available. |
Example
from maskyrag import generate_embeddings
print(generate_embeddings.list_embeddings_model())
Output
['sentence-transformers/all-MiniLM-L6-v2', 'BAAI/bge-small-en-v1.5', 'sentence-transformers/all-mpnet-base-v2', ...]
get_embeddings(model)
Creates instance of the embedding vector model
Parameters
| Name | Type | Description |
|---|---|---|
model |
str |
Model name. |
Returns
| Type | Description |
|---|---|
| langchain_huggingface.embeddings.huggingface.HuggingFaceEmbeddings | Embedding model instance. |
Example
from maskyrag import generate_embeddings
print(generate_embeddings.get_embeddings("sentence-transformers/all-MiniLM-L6-v2"))
Output
Loading weights: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 103/103 [00:00<00:00, 2358.80it/s]
model_name='sentence-transformers/all-MiniLM-L6-v2' cache_folder=None model_kwargs={} encode_kwargs={'normalize_embeddings': True} query_encode_kwargs={} multi_process=False show_progress=False
Vector Store
Generates Vectors and helps to search between vectors
get_vector_store(chunks, embeddings)
Generates vector from chunks, embeddings
Parameters
| Name | Type | Description |
|---|---|---|
chunks |
list |
List of documents. |
embeddings |
langchain_huggingface.embeddings.huggingface.HuggingFaceEmbeddings |
Embedding model. |
Returns
| Type | Description |
|---|---|
| langchain_community.vectorstores.faiss.FAISS | Vector Store Instance. |
Example
from maskyrag import generate_embeddings
from maskyrag import document_loaders
from maskyrag import document_splitter
from maskyrag import vector_store
file_name = "a.pdf"
documents = document_loaders.load_from_file_path(file_name)
chunks = document_splitter.get_chunks(documents, chunk_size=100, chunk_overlap=10)
embeddings = generate_embeddings.get_embeddings("sentence-transformers/all-MiniLM-L6-v2")
print(vector_store.get_vector_store(chunks, embeddings))
Output
<langchain_community.vectorstores.faiss.FAISS object at 0x...>
save_vector(identifier, vector_store)
Save the vector
Parameters
| Name | Type | Description |
|---|---|---|
identifier |
str |
Identifier to retrive the vector store. |
vector_store |
langchain_community.vectorstores.faiss.FAISS |
Vector store to save. |
Example
from maskyrag import generate_embeddings
from maskyrag import document_loaders
from maskyrag import document_splitter
from maskyrag import vector_store
file_name = "a.pdf"
documents = document_loaders.load_from_file_path(file_name)
chunks = document_splitter.get_chunks(documents, chunk_size=100, chunk_overlap=10)
embeddings = generate_embeddings.get_embeddings("sentence-transformers/all-MiniLM-L6-v2")
vector_store.save_vector("a", vector_store.get_vector_store(chunks, embeddings))
load_vector_store(identifier, embeddings)
Retrieve the saved vector
Parameters
| Name | Type | Description |
|---|---|---|
identifier |
str |
Identifier to retrive the vector store. |
embeddings |
langchain_huggingface.embeddings.huggingface.HuggingFaceEmbeddings |
Embedding model. |
Returns
| Type | Description |
|---|---|
| langchain_community.vectorstores.faiss.FAISS | Vector Store Instance. |
Example
from maskyrag import generate_embeddings
from maskyrag import document_loaders
from maskyrag import document_splitter
from maskyrag import vector_store
file_name = "a.pdf"
documents = document_loaders.load_from_file_path(file_name)
chunks = document_splitter.get_chunks(documents, chunk_size=100, chunk_overlap=10)
embeddings = generate_embeddings.get_embeddings("sentence-transformers/all-MiniLM-L6-v2")
vector_store.save_vector("a", vector_store.get_vector_store(chunks, embeddings))
print(vector_store.load_vector_store("a", embeddings))
Output
<langchain_community.vectorstores.faiss.FAISS object at 0x...>
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 maskyrag-0.0.1.tar.gz.
File metadata
- Download URL: maskyrag-0.0.1.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7e56fbd09bbcd72e4eaac59073a44a31a3bcaad3458de348ace929f5367dc9b
|
|
| MD5 |
0aaafeab8f4815dd945c44491e600451
|
|
| BLAKE2b-256 |
1faec44e7c991df2bee07a9505aee492da350532a6da8112d1626ced7598c8b3
|
File details
Details for the file maskyrag-0.0.1-py3-none-any.whl.
File metadata
- Download URL: maskyrag-0.0.1-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78e325ddd3dad99fa7cd8daeaab884d86089465cbb7c8809ed269e8fd939f58b
|
|
| MD5 |
fb55b7a32c70bee53d47fbfa9cf9fd66
|
|
| BLAKE2b-256 |
9d39f1c8f58836f3c0980858adad232bbb95fa08f491e58a1511784eadd1e1b5
|