01. PDF document based QA (Question-Answer)
Understanding RAG basic structure
1. Pre-processing -1~4 steps
In the pre-work phase, we proceed to a four-step that loads-split-embedding-save documents to the Vector DB (storage) of the data source.
1st level document load: brings up the document content.
2nd stage split (Text Split): Split documents to specific criteria (Chunk).
Step 3 Embedding: Embed and save the split (Chunk).
Step 4 Save VectorDB: Save embedded Chunk to DB.
2. RAG performance (RunTime) -5~8 steps
Copy
The name of the AI developed by the Samsung Electronics itself is'Samsung Gauss'.Copy
# Chain executive(Run Chain)
# Enter a query for the document and print out the answer.
question = "The name of the AI developed by Samsung Electronics is?"
response = chain.invoke(question)
print(response)Copy
Full code
Copy
Copy
Enter and run queries (questions) in the chain created.
Copy
Copy
Copy
Copy
Copy
Copy
Copy
Copy
Copy
Copy
Copy
(You can set various options for each step or apply new techniques.)
You can find the right structure for your document while changing the contents of each step-by-step module to suit your future situation.
Below is a skeleton code for understanding basic RAG structure.
Copy
RAG basic pipeline (1~8 steps)
Copy
Copy
LangSmith is not required, but useful. If you want to use LangSmith, after signing up from the link above, you need to set an environment variable to start logging tracking.
Applications built with LangChain will use LLM calls multiple times over multiple stages. As these applications become more and more complex, the ability to investigate exactly what is happening inside a chain or agent becomes very important. The best way to do this LangSmith Is to use.
Copy
Copy
Set API KEY.
Preferences
Files downloaded for practice data Please copy to folder
Author: Jaeheung Lee (AI Policy Institute Office Liability Institute), Lee Ji-soo (AI Policy Lab Yi Phyang Institute)
File name:
SPRI_AI_Brief_2023년12월호_F.pdf
Software Policy Institute (SPRi)-December 2023
Documents utilized for practice
5-step searcher (Retriever): Based on Query, search in DB to define the retriever to get results. Retriever is a search algorithm (Dense, Sparse) and is divided into retrievers. Dense: Similarity Based Search, Sparse: Keyword Based Search
6-step prompt: Generates a prompt to perform RAG. In the prompt context, the content retrieved from the document is entered. You can format the answer through prompt engineering.
Step 7 LLM: Define the model (GPT-3.5, GPT-4, Claude, etc..)
Step 8 Chain: Create a chain leading to the prompt - LLM - output.
Last updated