Skip to content

Commit

Permalink
Merge pull request #121 from kookmin-sw/feature/01
Browse files Browse the repository at this point in the history
fix: 문법, 속성 관련 chunk가 2개 이상일 때 발생하는 문제 수정
  • Loading branch information
SangwonYoon authored May 20, 2024
2 parents 28621e3 + ea667ae commit dcea41c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
21 changes: 12 additions & 9 deletions backend/app/retrieval/rag.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ def retrieve_doc(question, pc_index, embedding, llm):
retriever=vector_db.as_retriever(), llm=llm
)

logging.basicConfig()
logging.getLogger("langchain.retrievers.multi_query").setLevel(logging.INFO)

retrieved_docs = retriever_from_llm.get_relevant_documents(query=question)

doc_ids = [doc.metadata["doc-id"] for doc in retrieved_docs]
doc_ids = list(set([doc.metadata["doc-id"] for doc in retrieved_docs]))
docs = []

for doc_id in doc_ids:
Expand All @@ -31,14 +34,14 @@ def retrieve_doc(question, pc_index, embedding, llm):
"doc-id": {"$eq": doc_id},
"section_title": {"$eq": "통사론"},
},
top_k=1,
top_k=3,
include_metadata=True
)

if result_syntax["matches"]:
for idx in range(len(result_syntax["matches"])):
document = {
"title": result_syntax["matches"][0]["metadata"]["title"],
"content": result_syntax["matches"][0]["metadata"]["content"],
"title": result_syntax["matches"][idx]["metadata"]["title"],
"content": result_syntax["matches"][idx]["metadata"]["content"],
}
docs.append(document)

Expand All @@ -48,14 +51,14 @@ def retrieve_doc(question, pc_index, embedding, llm):
"doc-id": {"$eq": doc_id},
"section_title": {"$eq": "속성"},
},
top_k=1,
top_k=3,
include_metadata=True
)

if result_prop["matches"]:
for idx in range(len(result_prop["matches"])):
document = {
"title": result_prop["matches"][0]["metadata"]["title"],
"content": result_prop["matches"][0]["metadata"]["content"],
"title": result_prop["matches"][idx]["metadata"]["title"],
"content": result_prop["matches"][idx]["metadata"]["content"],
}
docs.append(document)

Expand Down
2 changes: 1 addition & 1 deletion backend/app/retrieval/rag_prototype.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
question = st.text_input('질문을 입력하세요:')

if question:
st.write(retrieve_doc(question, pc_index, embedding, llm=llm, top_k=5))
st.write(retrieve_doc(question, pc_index, embedding, llm=llm))

0 comments on commit dcea41c

Please sign in to comment.