Skip to main content

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

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.35.tar.gz (19.4 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.35-py2.py3-none-any.whl (20.5 MB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: eazyml_genai-0.2.35.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

Hashes for eazyml_genai-0.2.35.tar.gz
Algorithm Hash digest
SHA256 5665884b752b012483fd71d6123266cfa1dc9f6ffd3abe5972d28aad54a6e07e
MD5 9e847f74f16da5748f9640c5f5d56993
BLAKE2b-256 e92fddc981094ab283e6b9c9cc069d7706ad5072515b569a454b49dabd96c6af

See more details on using hashes here.

File details

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

File metadata

  • Download URL: eazyml_genai-0.2.35-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

Hashes for eazyml_genai-0.2.35-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 cca081f3b72db520e11b5dc03a3236e15bc941e89800fc16c279d3890db4413f
MD5 a669ea02d111b1e0d1302ed5961e3783
BLAKE2b-256 06f094679e4b64e4b7fc95e3c9130f5cbdb9ae18d8ad2eed5aea57b4e3dd4c43

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