diff --git a/applications/rag/frontend/container/application/rag_langchain/rag_chain.py b/applications/rag/frontend/container/application/rag_langchain/rag_chain.py index 901477365..36cc10859 100644 --- a/applications/rag/frontend/container/application/rag_langchain/rag_chain.py +++ b/applications/rag/frontend/container/application/rag_langchain/rag_chain.py @@ -60,15 +60,18 @@ def get_chat_history(session_id: str) -> PostgresChatMessageHistory: - history = PostgresChatMessageHistory.create_sync( - engine, session_id=session_id, table_name=CHAT_HISTORY_TABLE_NAME - ) - - logging.info( - f"Retrieving history for session {session_id} with {len(history.messages)}" - ) - return history + try: + history = PostgresChatMessageHistory.create_sync( + engine, session_id=session_id, table_name=CHAT_HISTORY_TABLE_NAME + ) + logging.info( + f"Retrieving history for session {session_id} with {len(history.messages)}" + ) + return history + except Exception as e: + logging.error(e) + return None def clear_chat_history(session_id: str): history = PostgresChatMessageHistory.create_sync( @@ -104,7 +107,7 @@ def create_chain() -> RunnableWithMessageHistory: ) return chain_with_history except Exception as e: - logging.info(e) + logging.error(e) raise e def take_chat_turn( @@ -115,5 +118,5 @@ def take_chat_turn( result = chain.invoke({"input": query_text}, config=config) return result except Exception as e: - logging.info(e) + logging.error(e) raise e diff --git a/applications/rag/frontend/container/application/vector_storages/cloud_sql.py b/applications/rag/frontend/container/application/vector_storages/cloud_sql.py index 6070ca817..b37724212 100644 --- a/applications/rag/frontend/container/application/vector_storages/cloud_sql.py +++ b/applications/rag/frontend/container/application/vector_storages/cloud_sql.py @@ -70,15 +70,12 @@ def add_texts( raise Exception(f"Error adding texts: {err}") def similarity_search( - self, query_input: dict, k: int = 4, **kwargs: Any + self, query: dict, k: int = 4, **kwargs: Any ) -> List[Document]: try: + query_input = query.get("input") query_vector = self.embeddings_service.embed_query(query_input) -<<<<<<< HEAD docs = self.vector_store.similarity_search_by_vector(query_vector, k=k) -======= - docs = self.vector_store.similarity_search_by_vector(query_vector, k=4) ->>>>>>> 2d652e30 (Rag langchain chat history (#755)) return docs except Exception as err: