taaha3244 commited on
Commit
eb10211
1 Parent(s): 04f5a93

Update retrieve.py

Browse files
Files changed (1) hide show
  1. retrieve.py +0 -40
retrieve.py CHANGED
@@ -17,46 +17,6 @@ os.environ["LANGFUSE_HOST"] = os.getenv("LANGFUSE_HOST")
17
  langfuse_handler = CallbackHandler()
18
 
19
 
20
-
21
-
22
- def retrieve_documents(query, api_key, qdrant_url, qdrant_api_key):
23
- """Retrieve documents based on the specified query."""
24
- embeddings_model = setup_openai_embeddings(api_key)
25
- qdrant_client = setup_qdrant_client(qdrant_url, qdrant_api_key)
26
- qdrant = Qdrant(client=qdrant_client, collection_name="Lex-v1", embeddings=embeddings_model)
27
- retriever = qdrant.as_retriever(search_kwargs={"k": 5})
28
- prompt = PromptTemplate(
29
- template="""
30
- # Your role
31
- You are a brilliant expert at understanding the intent of the questioner and the crux of the question, and providing the most optimal answer from the docs to the questioner's needs from the documents you are given.
32
- # Instruction
33
- Your task is to answer the question using the following pieces of retrieved context delimited by XML tags.
34
- <retrieved context>
35
- Retrieved Context:
36
- {context}
37
- </retrieved context>
38
- # Constraint
39
- 1. Think deeply and multiple times about the user's question\nUser's question:\n{question}\nYou must understand the intent of their question and provide the most appropriate answer.
40
- - Ask yourself why to understand the context of the question and why the questioner asked it, reflect on it, and provide an appropriate response based on what you understand.
41
- 2. Choose the most relevant content (the key content that directly relates to the question) from the retrieved context and use it to generate an answer.
42
- 3. Generate a concise, logical answer. When generating the answer, Do Not just list your selections, But rearrange them in context so that they become paragraphs with a natural flow.
43
- 4. When you don't have retrieved context for the question or if you have retrieved documents, but their content is irrelevant to the question, you should answer 'I can't find the answer to that question in the material I have'.
44
- 5. Use five sentences maximum. Keep the answer concise but logical/natural/in-depth.
45
- 6. At the end of the response provide metadata provided in the relevant docs, For example:"Metadata: page: 19, source: /content/OCR_RSCA/Analyse docs JVB + mails et convention FOOT INNOVATION.pdf'. Return just the page and source. Provide a list of all the metadata found in the relevant content formatted as bullets
46
- # Question:
47
- {question}""",
48
- input_variables=["context", "question"]
49
- )
50
- llm = openai_llm(api_key=api_key)
51
- rag_chain = (
52
- {"context": retriever | format_document_metadata, "question": RunnablePassthrough()}
53
- | prompt
54
- | llm
55
- | StrOutputParser()
56
- )
57
- return rag_chain.invoke(query,{"callbacks":[langfuse_handler]})
58
-
59
-
60
  def retrieve_documents_from_collection(query, api_key, qdrant_url, qdrant_api_key, collection_name):
61
  """Retrieve documents based on the specified query from a specific collection."""
62
  embeddings_model = setup_openai_embeddings(api_key)
 
17
  langfuse_handler = CallbackHandler()
18
 
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  def retrieve_documents_from_collection(query, api_key, qdrant_url, qdrant_api_key, collection_name):
21
  """Retrieve documents based on the specified query from a specific collection."""
22
  embeddings_model = setup_openai_embeddings(api_key)