pdfGPT Documentation

repository·main·Indexed 27 days ago

https://github.com/bhaskatripathi/pdfgpt

An open-source Retrieval-Augmented Generation (RAG) application for interacting with PDF documents via chat. It utilizes a lightweight architecture with Deep Averaging Network Encoders for semantic search, avoiding dependencies on LangChain or external Vector Databases. Features include automatic document chunking, page number citations, and an ask_api function for remote server interaction.

Tokens
724
Snippets
2
Records
4
Agent score
43%

What's inside pdfGPT

  1. Overview of pdfGPT architecture and capabilities

    main

    pdfGPT is a Retrieval-Augmented Generation (RAG) solution that allows users to chat with uploaded PDF files.

    Key Features:

    • No Third-Party API Dependencies: Does not rely on LangChain.
    • No VectorDB Required: Uses a unique architecture that employs embeddings without a dedicated vector database or indexing.
    • Semantic Search: Uses a Deep Averaging Network Encoder to generate embeddings and performs semantic search to find the most relevant content.
    • Precise Responses: Employs custom logic to generate answers that can include page number citations in square brackets (e.g., [page number]) to improve credibility.
    • Chunking: Automatically decomposes documents into smaller chunks (approximately 150 words) for processing.
  2. Optimize model performance for Q&A

    main

    When using pdfGPT, the choice of OpenAI model affects response quality, especially when embedding similarity is low:

    • Turbo Models (e.g., gpt-3.5-turbo): These are chat completion models. They may provide poor responses in cases where embedding similarity is low, despite OpenAI's claims.
    • Recommended Models: For high-accuracy Q&A, use text-davinci-003 or GPT-4 and above. These models are more reliable for retrieving relevant output from the retrieved chunks.
  3. Use the ask_api function to interact with the PDF processing engine

    main

    The ask_api function allows you to send questions about a PDF to a remote server hosted at lcserve_host. You can provide either a PDF via a URL or by uploading a file. The function requires an OpenAI API key to be passed within the request to the backend.

    Parameters:

    • lcserve_host (str): The base URL of the API server (must start with http).
    • url (str): The direct URL to a PDF file. If provided, the function calls the /ask_url endpoint.
    • file (_TemporaryFileWrapper): A temporary file object containing the PDF. If provided, the function calls the /ask_file endpoint.
    • question (str): The text query you want to ask about the PDF.
    • openAI_key (str): Your OpenAI API key.

    Constraints:

    • You must provide either a url or a file, but not both and not neither.
    • The lcserve_host must start with http.
    • The question cannot be empty.

    Returns:

    • A str containing the answer/result from the server.

    Errors:

    • Returns error strings starting with [ERROR]: for validation failures.
    • Raises a ValueError if the server response status code is not 200.
    def ask_api(
        lcserve_host: str,
        url: str,
        file: _TemporaryFileWrapper,
        question: str,
        openAI_key: str,
    ) -> str: