This package enables Retrieval-Augmented Generation (RAG) for PDF documents, enhancing the ability of Generative AI models to provide accurate and contextually relevant responses based on your document content.
Project description
EazyML Responsible-AI: Counterfactual
The eazyml-genai framework offers a robust and professional solution for developing knowledge-intensive applications, seamlessly integrating document processing, advanced retrieval techniques, and generative language models. It is particularly well-suited for applications demanding robust question-answering capabilities over extensive PDF document repositories, with a key feature being its ability to provide precise provenance for generated answers by citing the specific PDF file and corresponding page number, thereby facilitating user verification and enhancing trust in the system's output.
Features
- Document Ingestion and Structuring: The system is equipped to process PDF documents, extracting textual content and converting it into a structured JSON format. This process facilitates efficient downstream processing and retrieval.
- Advanced Embedding Generation: To enable semantic search and relevance scoring, the framework supports the generation of both sparse and dense vector embeddings. This includes integration with state-of-the-art embedding models from prominent providers such as OpenAI, Google (e.g., Vertex AI Embeddings), and Hugging Face Transformers. This dual approach allows for capturing both lexical and semantic relationships within the document corpus.
- Vector Database Integration: The generated vector embeddings are efficiently indexed and managed within high-performance vector databases, specifically supporting Qdrant and Pinecone. These integrations enable rapid and scalable retrieval of relevant document segments based on vector similarity.
- Hybrid Retrieval Mechanism: The retrieval pipeline is engineered to support hybrid search strategies, combining the strengths of sparse and dense vector retrieval. This allows for a more comprehensive and nuanced identification of relevant information, considering both keyword matching and semantic understanding.
- Generative Model Augmentation: The core functionality of this RAG framework lies in its ability to augment the input to generative language models. By retrieving and injecting relevant document excerpts into the prompt, the system provides the necessary context for the language model to generate more informed, accurate, and contextually appropriate responses. This significantly mitigates the issue of hallucination and enhances the overall reliability of the generated content.
- Citation: Its ability to provide precise provenance for generated answers, and citing the specific PDF file and corresponding page number, thereby facilitating user verification and enhancing trust in the system's output.
Installation
User installation
The easiest way to install counterfactual package is using pip:
pip install -U eazyml-genai
Dependencies
EazyML Generative AI requires :
- numpy
- pandas
- nltk
- doclayout-yolo
- torchvision
- PyMuPDF
- pinecone
- qdrant-client
- sentence-transformers
- google-genai
- google-cloud-aiplatform
- openai
- anthropic
Usage
This EazyML GenAI package lets you turn PDFs into searchable JSONs. It uses smart techniques (sparse and dense vector embeddings from OpenAI, Google, or Hugging Face) with vector databases like Qdrant and Pinecone to find the most relevant parts of your documents.
Then, it feeds this information to a generative AI to get better, more accurate answers to your questions. It's all about making AI responses smarter by giving them the right context from your documents.
Imports
import os
from eazyml_genai import ez_init
from eazyml_genai.components import PDFLoader
from eazyml_genai.components import QdrantDB
from eazyml_genai.components import GoogleGM
from eazyml_genai.components import(
GoogleEmbeddingModel
)
Initialize and load PDF Document
# Initialize the EazyML library.
_ = ez_init()
# process pdf documents with unstructured data into semi-structured data or in json format
pdf_loader = PDFLoader(max_chunk_words=1000)
documents = pdf_loader.load(file_path=r'YOUR PDF FILE')
# set your api key below
os.environ['GEMINI_API_KEY'] = "YOUR GOOGLE API KEY"
Index your document
# give a name to collection which can hold multiple pdf documents
collection_name = 'yolo'
# initialize vector database such as qdrant or pinecone
qdrant_db = QdrantDB(location=':memory:')
# index your document in vector database by giving text/image embedding model
# you could use huggingface/openai/google embedding model for text embedding model
qdrant_db.index_documents(collection_name=collection_name,
documents=documents,
text_embedding_model=GoogleEmbeddingModel.TEXT_EMBEDDING_004,
)
Retrieve relevant document for given question
question = 'YOUR QUESTION'
# retrieved document from vector database
total_hits = qdrant_db.retrieve_documents(collection_name, question, top_k=5)
# get json format document
payloads = [hit.payload for hit in total_hits]
Sample Output Preview
# initialized generative model such as Google/OpenAI
google_gm = GoogleGM(model="gemini-2.0-flash",
api_key=os.getenv('GEMINI_API_KEY'))
# generated response, total input token and output token
response, input_tokens, output_tokens = google_gm.predict(question=question,
payloads=payloads,
show_token_details=True
)
You can find more information in the documentation.
Useful links, other packages from EazyML family
-
If you have questions or would like to discuss a use case, please contact us here
-
Here are the other packages from EazyML suite:
- eazyml-automl: eazyml-automl provides a suite of APIs for training, optimizing and validating machine learning models with built-in AutoML capabilities, hyperparameter tuning, and cross-validation.
- eazyml-data-quality: eazyml-data-quality provides APIs for comprehensive data quality assessment, including bias detection, outlier identification, and drift analysis for both data and models.
- eazyml-counterfactual: eazyml-counterfactual provides APIs for optimal prescriptive analytics, counterfactual explanations, and actionable insights to optimize predictive outcomes to align with your objectives.
- eazyml-insight: eazyml-insight provides APIs to discover patterns, generate insights, and mine rules from your datasets.
- eazyml-xai: eazyml-xai provides APIs for explainable AI (XAI), offering human-readable explanations, feature importance, and predictive reasoning.
- eazyml-xai-image: eazyml-xai-image provides APIs for image explainable AI (XAI).
License
This project is licensed under the Proprietary License.
Maintained by EazyML
© 2025 EazyML. All rights reserved.
Project details
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 eazyml_genai-0.2.36.tar.gz.
File metadata
- Download URL: eazyml_genai-0.2.36.tar.gz
- Upload date:
- Size: 19.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c5c4e9a4f0396adc8050652971ad5a076b2c16297e3c8cc54fb311fe6927120b
|
|
| MD5 |
aed2ca1ff94fdc097d635a3f815b290c
|
|
| BLAKE2b-256 |
27039dbe730aad8ca0bb5c26ec1e42a214ff26adea7115db6732b914f45b08ab
|
File details
Details for the file eazyml_genai-0.2.36-py2.py3-none-any.whl.
File metadata
- Download URL: eazyml_genai-0.2.36-py2.py3-none-any.whl
- Upload date:
- Size: 20.5 MB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7b108ac3507d733a29f24b71c112a10baa8ed2d0ce7c707340e3aca99684c98
|
|
| MD5 |
fda1830eff5bc9db417e03a92244bf72
|
|
| BLAKE2b-256 |
7364057dc92fbbc639c78ea11f2a0ad1d297a803a722511ae15af1f423ac854e
|