Skip to main content

A Generative AI based package to support RAG capabilities on pdf documents.

Project description

EazyML Responsible-AI: Counterfactual

Python PyPI package Code Style

EazyML

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

  • Documentation

  • Homepage

  • 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

eazyml_genai-0.2.31.tar.gz (19.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

eazyml_genai-0.2.31-py2.py3-none-any.whl (20.3 MB view details)

Uploaded Python 2Python 3

File details

Details for the file eazyml_genai-0.2.31.tar.gz.

File metadata

  • Download URL: eazyml_genai-0.2.31.tar.gz
  • Upload date:
  • Size: 19.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.17

File hashes

Hashes for eazyml_genai-0.2.31.tar.gz
Algorithm Hash digest
SHA256 340f42cae8c89e350d8f89bf3bddd6b7c905116f21d28d2202ae0aacdfbd0b7d
MD5 246d5186ad182f74240f5716c6d37838
BLAKE2b-256 2e0dafbe033254d63cdd6fb14df1c1e083b8d7766f162980315b97ba1166d109

See more details on using hashes here.

File details

Details for the file eazyml_genai-0.2.31-py2.py3-none-any.whl.

File metadata

  • Download URL: eazyml_genai-0.2.31-py2.py3-none-any.whl
  • Upload date:
  • Size: 20.3 MB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.17

File hashes

Hashes for eazyml_genai-0.2.31-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 36d3a03b370084884fafb0986e3d20808cdb43844f39b2bfe9df697f7f04d8d1
MD5 63d235bbf7333f4ed0ebd95db3a9b360
BLAKE2b-256 3e099557132c980f495e083fe019d2762dd95f110368727fa3742891856f9d26

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page