Skip to content

Commit

Permalink
Merge pull request #54 from arjbingly/project-BasicRAG
Browse files Browse the repository at this point in the history
cookbook for Basic RAG
  • Loading branch information
arjbingly authored Mar 26, 2024
2 parents 046ed0e + 1c02173 commit 2ecafa7
Show file tree
Hide file tree
Showing 16 changed files with 211 additions and 265 deletions.
13 changes: 0 additions & 13 deletions projects/Basic-RAG/BasciRAG_CustomPrompt.py

This file was deleted.

87 changes: 0 additions & 87 deletions projects/Basic-RAG/BasicRAG-ingest_data.py

This file was deleted.

14 changes: 14 additions & 0 deletions projects/Basic-RAG/BasicRAG_CustomPrompt.py
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)
25 changes: 13 additions & 12 deletions projects/Basic-RAG/BasicRAG_FewShotPrompt.py
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)
13 changes: 13 additions & 0 deletions projects/Basic-RAG/BasicRAG_ingest.py
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)
8 changes: 7 additions & 1 deletion projects/Basic-RAG/BasicRAG_refine.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
from grag.grag.rag import BasicRAG
"""A cookbook demonstrating how to use Basic RAG with refine chain using DeepLake as client."""

from grag.components.multivec_retriever import Retriever
from grag.components.vectordb.deeplake_client import DeepLakeClient
from grag.rag.basic_rag import BasicRAG

client = DeepLakeClient(collection_name="test")
retriever = Retriever(vectordb=client)
rag = BasicRAG(doc_chain="refine")

if __name__ == "__main__":
Expand Down
2 changes: 2 additions & 0 deletions projects/Basic-RAG/BasicRAG_stuff.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""A cookbook demonstrating how to use Basic RAG with stuff chain using DeepLake as client."""

from grag.components.multivec_retriever import Retriever
from grag.components.vectordb.deeplake_client import DeepLakeClient
from grag.rag.basic_rag import BasicRAG
Expand Down
42 changes: 0 additions & 42 deletions projects/Basic-RAG/BasicRAG_v1_depricated.py

This file was deleted.

52 changes: 0 additions & 52 deletions projects/Basic-RAG/BasicRAG_v2_depricated.py

This file was deleted.

19 changes: 11 additions & 8 deletions projects/Basic-RAG/README.md
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.
12 changes: 0 additions & 12 deletions projects/Basic-RAG/tests/BasicRAG_v1_test.py

This file was deleted.

12 changes: 0 additions & 12 deletions projects/Basic-RAG/tests/BasicRAG_v2_test.py

This file was deleted.

Loading

0 comments on commit 2ecafa7

Please sign in to comment.