Chat with your own Document using PrivateGPT

Posted By :Ishandeep Singh |30th July 2023

Chat with your own Document Using PrivateGPT


PrivateGPT is a programme that allows you to ask questions about your documents without requiring an online connection, thanks to the power of Language Models. It is completely private, with no data leaving your execution environment at any stage. You can ingest documents and ask inquiries even without an internet connection!

How privateGPT works 

This project is Divided into two phases 1.)Ingest Phase ( file)  ,  2.)Query Phase ( file)


Workings of Ingest Phase( file)
In our privateGPT project it takes the data from the source_document folder, split it into chunks and chunk overlaps by using RecursiveCharacterTextSplitter class.



with the help of HuggingFaceEmbeddings(SentenceTransformers) and all-MiniLM-L6-v2  Model, it embed the text.


Embeddings are refers to the process of converting text or words into numerical representation (vectors) that can be understand and processed by machine learning algorithm. these text or words embeddings are essential for many Natural Language Processing tasks as they capture semantic relationships and contextual information between words, enabling machine to understand the meaning of the words and sentence in a numerical format.
words with similar meanings or contexts are mapped closer together in the vector space. this allows machine learning models to leverage the similarities between words and make more informed decisions based on the context in which words appear.

overall, text or word embeddings play a crucial role in bridging the gap between human language and machine learning algorithm, enabling computers to process and understand Natural language text more effectively.


after creating the Embeddings we store into our Chroma DB
Chroma is a powerful toolset that allows developers to work with embeddings, store, index, and query these embeddings effectively and efficiently, and perform similarity searches on large-scale datasets.



Working of Query Phase( file)
In this phase the user input serves as a query that is passed to the local Language Model (LLM) for processing and generating an answer. The LLM processes the query and produces an answer based on the context retrieved from the local vector database.

User Input: The user provides a natural language text query, which serves as the input question.

LLM Processing: The script uses a local LLM (GPT4All-J or LlamaCpp) to process the user's question. The LLM has been pre-trained on a vast corpus of text and is capable of understanding Natural language and generating relevant responses.


Context Retrieval: The script performs a similarity search using the local vector database (Chroma) to retrieve relevant context from the ingested documents by using RetrievalQA. The context consists of a selection of documents that are most similar to the user's query.


Answer Generation: The LLM generates an answer based on the user's question and the context retrieved from the vector database. The LLM uses its language modeling capabilities to produce a response that fits the given context.


Displaying the Answer: The script displays the answer generated by the LLM and presents the four sources (documents) used as context for generating that answer. This information helps the user understand how the LLM arrived at the response.



In summary, the user input is used as a query for the local LLM, and the LLM leverages the vector embeddings of the ingested documents (retrieved from the local vector database) to generate a relevant answer. The process does not directly create embeddings for the user input but rather uses embeddings of the documents to contextualize the LLM's response to the user's query.

About Author

Ishandeep Singh

Ishandeep Singh is a proficient Backend Developer with a strong skill set in Python and Django. In addition, he has a sound understanding of various other technologies as well such as HTML, CSS, JavaScript, and Node.js.He has contributed to various projects namely TripCongo project where he has utilized his skills and proficiency to deliver a successful outcome.

Request For Proposal

[contact-form-7 404 "Not Found"]

Ready to innovate ? Let's get in touch

Chat With Us