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.34.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.34-py2.py3-none-any.whl (20.3 MB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: eazyml_genai-0.2.34.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.34.tar.gz
Algorithm Hash digest
SHA256 1fc2bdbe385a48a7803e7122cadfd589d2fc0ad346f7a8ee454685c6ea88a3a2
MD5 90449a5f9596b70205a4f1b4b21cacb0
BLAKE2b-256 d2cd168a7185ea53a781ee31b815cd32563345df96a821a1b4bcd47928e9d11f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: eazyml_genai-0.2.34-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.34-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 69d6d34b7d5ffb665aebde7461308d46bf46bae7de48061e9ea3e5b34701ff81
MD5 19018a441ff0d0890c2847bb1c087d4b
BLAKE2b-256 5a0e2a8ccc34602aa7a5f7fe438f08e540a219ee7f20dc5a8780bf599307e834

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