Update services/rag_pipeline.py
Browse files- services/rag_pipeline.py +24 -21
services/rag_pipeline.py
CHANGED
@@ -1,21 +1,24 @@
|
|
1 |
-
# from retriever.vectordb import search_documents
|
2 |
-
from retriever.vectordb_rerank import search_documents
|
3 |
-
from generator.prompt_builder import build_prompt
|
4 |
-
from generator.llm_inference import generate_answer
|
5 |
-
|
6 |
-
def rag_pipeline(query: str, top_k: int = 5) -> str:
|
7 |
-
"""
|
8 |
-
1. ์ฌ์ฉ์ ์ง๋ฌธ์ผ๋ก ๊ด๋ จ ๋ฌธ์๋ฅผ ๊ฒ์
|
9 |
-
2. ๊ฒ์๋ ๋ฌธ์์ ํจ๊ป ํ๋กฌํํธ ๊ตฌ์ฑ
|
10 |
-
3. ํ๋กฌํํธ๋ก๋ถํฐ ๋ต๋ณ ์์ฑ
|
11 |
-
"""
|
12 |
-
# 1. ๊ฒ์
|
13 |
-
context_docs = search_documents(query, top_k=top_k)
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
1 |
+
# from retriever.vectordb import search_documents
|
2 |
+
from retriever.vectordb_rerank import search_documents
|
3 |
+
from generator.prompt_builder import build_prompt
|
4 |
+
from generator.llm_inference import generate_answer
|
5 |
+
|
6 |
+
def rag_pipeline(query: str, top_k: int = 5) -> str:
|
7 |
+
"""
|
8 |
+
1. ์ฌ์ฉ์ ์ง๋ฌธ์ผ๋ก ๊ด๋ จ ๋ฌธ์๋ฅผ ๊ฒ์
|
9 |
+
2. ๊ฒ์๋ ๋ฌธ์์ ํจ๊ป ํ๋กฌํํธ ๊ตฌ์ฑ
|
10 |
+
3. ํ๋กฌํํธ๋ก๋ถํฐ ๋ต๋ณ ์์ฑ
|
11 |
+
"""
|
12 |
+
# 1. ๊ฒ์
|
13 |
+
context_docs = search_documents(query, top_k=top_k)
|
14 |
+
print("context_docs", context_docs)
|
15 |
+
|
16 |
+
# 2. ํ๋กฌํํธ ์กฐ๋ฆฝ
|
17 |
+
prompt = build_prompt(query, context_docs)
|
18 |
+
print("prompt", prompt)
|
19 |
+
|
20 |
+
# 3. ๋ชจ๋ธ ์ถ๋ก
|
21 |
+
output = generate_answer(prompt)
|
22 |
+
print("output", output)
|
23 |
+
|
24 |
+
return output
|