ArturG9 commited on
Commit
de0cc6e
1 Parent(s): e8603c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -20
app.py CHANGED
@@ -84,28 +84,28 @@ def create_retriever_from_chroma(vectorstore_path="docs/chroma/", search_type='m
84
  vectorstore = Chroma.from_documents(
85
  documents=split_docs, embedding=embeddings, persist_directory=vectorstore_path
86
  )
 
 
 
87
 
88
- metadata_field_info = [
89
- AttributeInfo(
90
- name="source",
91
- description="The document chunk is from, should be one of documents in data folder`, or `docs/cs229_lectures/MachineLearning-Lecture03.pdf`",
92
- type="string",
93
- ),
94
- AttributeInfo(
95
- name="page",
96
- description="The page from the document",
97
- type="integer",
98
- ),
99
- ]
100
- document_content_description = "Respublic of Lithuania law documents"
101
- retriever = SelfQueryRetriever.from_llm(
102
- llm,
103
- vectorstore,
104
- document_content_description,
105
- metadata_field_info,
106
- verbose=True
107
  )
108
- return retriever
 
 
 
109
 
110
 
111
 
 
84
  vectorstore = Chroma.from_documents(
85
  documents=split_docs, embedding=embeddings, persist_directory=vectorstore_path
86
  )
87
+
88
+
89
+ retriever=vectorstore.as_retriever(search_type='mmr', search_kwargs={"k": 7})
90
 
91
+ contextualize_q_system_prompt = """If the question is not clear, given a chat history and the latest user question
92
+ which maybe reference context, formulate a standalone question,
93
+ which can be understood without the chat history. Do NOT answer the question,
94
+ just reformulate it if needed and otherwise return it as is."""
95
+
96
+ )
97
+
98
+ contextualize_q_prompt = ChatPromptTemplate.from_messages(
99
+ [
100
+ ("system", contextualize_q_system_prompt),
101
+ MessagesPlaceholder("chat_history"),
102
+ ("human", "{input}"),
103
+ ]
 
 
 
 
 
 
104
  )
105
+
106
+ ha_retriever = create_history_aware_retriever(llm, retriever, contextualize_q_prompt)
107
+
108
+ return ha_retriever
109
 
110
 
111