Ask questions to your documents without an internet connection, using the power of LLMs. 100% private, no data leaves your execution environment at any point. You can ingest documents and ask questions without an internet connection!
Built with LangChain and GPT4All
In order to set your environment up to run the code here, first install all requirements:
pip install -r requirements.txt
Then, download the 2 models and place them in a folder called ./models
:
- LLM: default to ggml-gpt4all-j-v1.3-groovy.bin. If you prefer a different GPT4All-J compatible model, just download it and reference it in
privateGPT.py
. - Embedding: default to ggml-model-q4_0.bin. If you prefer a different compatible Embeddings model, just download it and reference it in
privateGPT.py
andingest.py
.
This repo uses a state of the union transcript as an example.
Place your .txt file in source_documents
folder.
Edit ingest.py
loader to point it to your document.
Run the following command to ingest the data.
python ingest.py
It will create a db
folder containing the local vectorstore. Will take time, depending on the size of your document.
You can ingest as many documents as you want by running ingest
, and all will be accumulated in the local embeddings database.
If you want to start from scracth, delete the db
folder.
Note: during the ingest process no data leaves your local environment. You could ingest without an internet connection.
In order to ask a question, run a command like:
python privateGPT.py
And wait for the script to require your input.
> Enter a query:
Hit enter. You'll see the LLM print the context it is using from your documents and then the final answer; you can then ask another question without re-running the script, just wait for the prompt again.
Note: you could turn off your internet connection, and the script inference would still work. No data gets out of your local environment.
Type exit
to finish the script.
Selecting the right local models and the power of LangChain
you can run the entire pipeline locally, without any data leaving your environment, and with reasonable performance.
ingest.py
usesLangChain
tools to parse the document and create embeddings locally usingLlamaCppEmbeddings
. It then stores the result in a local vector database usingChroma
vector store.privateGPT.py
uses a local LLM based onGPT4All
to understand questions and create answers. The context for the answers is extracted from the local vector store using a similarity search to locate the right piece of context from the docs.gpt4all_j.py
is a wrapper to supportGPT4All-J
models within LangChain. It was created given such support didn't exist at the moment of creation of this project (onlyGPT4All
models where supported). It will be proposed as a contribution to the officialLangChain
repo soon.
This is a test project to validate the feasibility of a fully private solution for question answering using LLMs and Vector embeddings. It is not production ready, and it is not meant to be used in production. The models selection is not optimized for performance, but for privacy; but it is possible to use different models and vectorstores to improve performance.