diff --git a/A2rchi/chains/chain.py b/A2rchi/chains/chain.py index c60e603..0ed1233 100644 --- a/A2rchi/chains/chain.py +++ b/A2rchi/chains/chain.py @@ -50,20 +50,26 @@ def __init__(self): self.chain = BaseChain.from_llm(self.llm, self.vectorstore.as_retriever(), return_source_documents=True) - update_vectorstore_thread = Thread(target=self.update_vectorstore) - update_vectorstore_thread.start() + # update_vectorstore_thread = Thread(target=self.update_vectorstore) + # update_vectorstore_thread.start() + + + # def update_vectorstore(self): + # while not self.kill: + # time.sleep(1000) + # self.lock.acquire() + # self.vectorstore = self.dataManager.fetch_vectorstore() + # self.chain = BaseChain.from_llm(self.llm, self.vectorstore.as_retriever(), return_source_documents=True) + # print("Updated chain with new vectorstore") + # self.lock.release() + # return None + def update_vectorstore(self): - while not self.kill: - time.sleep(1000) - self.lock.acquire() - self.vectorstore = self.dataManager.fetch_vectorstore() - self.chain = BaseChain.from_llm(self.llm, self.vectorstore.as_retriever(), return_source_documents=True) - print("Updated chain with new vectorstore") - self.lock.release() - return None - + self.vectorstore = self.dataManager.fetch_vectorstore() + self.chain = BaseChain.from_llm(self.llm, self.vectorstore.as_retriever(), return_source_documents=True) + return def __call__(self, history): @@ -89,5 +95,3 @@ def __call__(self, history): answer = self.chain({"question": question, "chat_history": prev_history}) self.lock.release() return answer - - diff --git a/A2rchi/interfaces/chat_app.py b/A2rchi/interfaces/chat_app.py index 68764b2..96b64ff 100644 --- a/A2rchi/interfaces/chat_app.py +++ b/A2rchi/interfaces/chat_app.py @@ -130,6 +130,7 @@ def __call__(self, inp: str, history: Optional[Tuple[str, str]], discussion_id: # Get similarity score to see how close the input is to the source # Low score means very close (it's a distance between embedding vectors approximated # by an approximate k-nearest neighbors algoirthm) + self.chain.update_vectorstore() score = self.chain.vectorstore.similarity_search_with_score(inp)[0][1] #Get the closest source to the document @@ -205,4 +206,4 @@ def launch(self, _debug = True, _share = True): message.submit(fn = self.chat, inputs = [message, state, id_state], outputs=[chatbot, state, id_state]) - self.block.launch(debug=_debug, share=_share) \ No newline at end of file + self.block.launch(debug=_debug, share=_share) diff --git a/deploy/compose.yaml b/deploy/compose.yaml index fffe650..c82f2e9 100644 --- a/deploy/compose.yaml +++ b/deploy/compose.yaml @@ -39,7 +39,7 @@ services: volumes: - a2rchi-data:/root/data/ ports: - - 7861:7860 + - 7861:7860 # host:container mailbox: build: