Skip to content

Commit cf709a6

Browse files
committed
feat: Get answers using preferred number of chunks
1 parent 573c436 commit cf709a6

3 files changed

Lines changed: 5 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ PERSIST_DIRECTORY: is the folder you want your vectorstore in
2222
MODEL_PATH: Path to your GPT4All or LlamaCpp supported LLM
2323
MODEL_N_CTX: Maximum token limit for the LLM model
2424
EMBEDDINGS_MODEL_NAME: SentenceTransformers embeddings model name (see https://www.sbert.net/docs/pretrained_models.html)
25+
TARGET_SOURCE_CHUNKS: The amount of chunks (sources) that will be used to answer a question
2526
```
2627

2728
Note: because of the way `langchain` loads the `SentenceTransformers` embeddings, the first time you run the script it will require internet connection to download the embeddings model itself.

example.env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ PERSIST_DIRECTORY=db
22
MODEL_TYPE=GPT4All
33
MODEL_PATH=models/ggml-gpt4all-j-v1.3-groovy.bin
44
EMBEDDINGS_MODEL_NAME=all-MiniLM-L6-v2
5-
MODEL_N_CTX=1000
5+
MODEL_N_CTX=1000
6+
TARGET_SOURCE_DOCUMENTS=4

privateGPT.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
model_type = os.environ.get('MODEL_TYPE')
1717
model_path = os.environ.get('MODEL_PATH')
1818
model_n_ctx = os.environ.get('MODEL_N_CTX')
19+
target_source_chunks = int(os.environ.get('TARGET_SOURCE_CHUNKS',4))
1920

2021
from constants import CHROMA_SETTINGS
2122

@@ -24,7 +25,7 @@ def main():
2425
args = parse_arguments()
2526
embeddings = HuggingFaceEmbeddings(model_name=embeddings_model_name)
2627
db = Chroma(persist_directory=persist_directory, embedding_function=embeddings, client_settings=CHROMA_SETTINGS)
27-
retriever = db.as_retriever()
28+
retriever = db.as_retriever(search_kwargs={"k": target_source_chunks})
2829
# activate/deactivate the streaming StdOut callback for LLMs
2930
callbacks = [] if args.mute_stream else [StreamingStdOutCallbackHandler()]
3031
# Prepare the LLM

0 commit comments

Comments
 (0)