Skip to content

Commit

Permalink
temporarily not using lock w/update for vectorstore
Browse files Browse the repository at this point in the history
  • Loading branch information
mdr223 committed Sep 8, 2023
1 parent 350b19e commit ab467e7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
30 changes: 17 additions & 13 deletions A2rchi/chains/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -89,5 +95,3 @@ def __call__(self, history):
answer = self.chain({"question": question, "chat_history": prev_history})
self.lock.release()
return answer


3 changes: 2 additions & 1 deletion A2rchi/interfaces/chat_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
self.block.launch(debug=_debug, share=_share)
2 changes: 1 addition & 1 deletion deploy/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ services:
volumes:
- a2rchi-data:/root/data/
ports:
- 7861:7860
- 7861:7860 # host:container

mailbox:
build:
Expand Down

0 comments on commit ab467e7

Please sign in to comment.