-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from arjbingly/project-BasicRAG
cookbook for Basic RAG
- Loading branch information
Showing
16 changed files
with
211 additions
and
265 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"""A cookbook demonstrating how to use custom prompts with Basic RAG.""" | ||
|
||
from grag.components.prompt import Prompt | ||
from grag.rag.basic_rag import BasicRAG | ||
|
||
custom_prompt = Prompt( | ||
input_keys={"context", "question"}, | ||
template="""Answer the following question based on the given context. | ||
question: {question} | ||
context: {context} | ||
answer: | ||
""", | ||
) | ||
rag = BasicRAG(doc_chain="stuff", custom_prompt=custom_prompt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,30 @@ | ||
"""A cookbook demonstrating how to use custom few-shot prompts with Basic RAG.""" | ||
|
||
from grag.components.prompt import FewShotPrompt | ||
from grag.rag.basic_rag import BasicRAG | ||
from grap.components.prompt import FewShotPrompt | ||
|
||
custom_few_shot_prompt = FewShotPrompt( | ||
input_keys={"context", "question"}, | ||
output_keys={"answer"}, | ||
example_template=''' | ||
example_template=""" | ||
question: {question} | ||
answer: {answer} | ||
''', | ||
prefix='''Answer the following question based on the given context like examples given below:''', | ||
suffix='''Answer the following question based on the given context | ||
""", | ||
prefix="""Answer the following question based on the given context like examples given below:""", | ||
suffix="""Answer the following question based on the given context | ||
question: {question} | ||
context: {context} | ||
answer: | ||
''', | ||
""", | ||
examples=[ | ||
{ | ||
"question": "What is the name of largest planet?", | ||
"answer": "Jupiter is the largest planet." | ||
"answer": "Jupiter is the largest planet.", | ||
}, | ||
{ | ||
"question": "Who came up with Convolutional Neural Networks?", | ||
"answer": "Yann LeCun introduced convolutional neural networks." | ||
} | ||
] | ||
"answer": "Yann LeCun introduced convolutional neural networks.", | ||
}, | ||
], | ||
) | ||
rag = BasicRAG(doc_chain="stuff", | ||
custom_prompt=custom_few_shot_prompt) | ||
rag = BasicRAG(doc_chain="stuff", custom_prompt=custom_few_shot_prompt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
"""A cookbook demonstrating how to ingest pdf files for use with Basic RAG.""" | ||
|
||
from pathlib import Path | ||
|
||
from grag.components.multivec_retriever import Retriever | ||
from grag.components.vectordb.deeplake_client import DeepLakeClient | ||
|
||
client = DeepLakeClient(collection_name="test") | ||
retriever = Retriever(vectordb=client) | ||
|
||
dir_path = Path(__file__).parents[2] / "data/client_test/test/" | ||
|
||
retriever.ingest(dir_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
# Basic RAG | ||
# Basic RAG Cookbook | ||
|
||
## BasicRAG v1 | ||
Welcome to the Basic RAG Cookbook! This repository is dedicated to showcasing how to utilize the Retrieval-Augmented | ||
Generation (RAG) model for various applications using custom and few-shot prompts. For in depth understanding of RAG | ||
pipelines, chains, and prompts | ||
check [RAG-Piplines.md](https://github.com/arjbingly/Capstone_5/blob/main/projects/Basic-RAG/RAG-Piplines.md) | ||
|
||
- Stuff document chain (Refer [RAG-Pipelines.md](./RAG-Piplines.md)) | ||
- Top-k retrival | ||
### Contents: | ||
|
||
## BasicRAG v2 | ||
|
||
- Refine document chain (Refer [RAG-Pipelines.md](./RAG-Piplines.md)) | ||
- Top-k retrival | ||
- **BasicRAG_CustomPrompt.py**: Learn to integrate custom prompts into Basic RAG for tailored query responses. | ||
- **BasicRAG_FewShotPrompt.py**: Explore the use of few-shot prompts to enhance Basic RAG's contextual understanding. | ||
- **BasicRAG_ingest.py**: Demonstrates the process of ingesting PDF files, making them searchable via Basic RAG. | ||
- **BasicRAG_stuff.py**: A guide on leveraging the stuff chain with Basic RAG for enriched data processing. | ||
- **BasicRAG_refine.py**: Discover how to refine queries using the refine chain for more precise results with Basic RAG. |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.