From 20e4f6cc164564254d0db08eb11248fc2644c25d Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Tue, 18 Jun 2024 14:55:18 -0700 Subject: [PATCH] refac --- backend/apps/rag/utils.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/backend/apps/rag/utils.py b/backend/apps/rag/utils.py index d0570f748..7b4324d9a 100644 --- a/backend/apps/rag/utils.py +++ b/backend/apps/rag/utils.py @@ -237,7 +237,7 @@ def get_embedding_function( def get_rag_context( - docs, + files, messages, embedding_function, k, @@ -245,29 +245,29 @@ def get_rag_context( r, hybrid_search, ): - log.debug(f"docs: {docs} {messages} {embedding_function} {reranking_function}") + log.debug(f"files: {files} {messages} {embedding_function} {reranking_function}") query = get_last_user_message(messages) extracted_collections = [] relevant_contexts = [] - for doc in docs: + for file in files: context = None collection_names = ( - doc["collection_names"] - if doc["type"] == "collection" - else [doc["collection_name"]] + file["collection_names"] + if file["type"] == "collection" + else [file["collection_name"]] ) collection_names = set(collection_names).difference(extracted_collections) if not collection_names: - log.debug(f"skipping {doc} as it has already been extracted") + log.debug(f"skipping {file} as it has already been extracted") continue try: - if doc["type"] == "text": - context = doc["content"] + if file["type"] == "text": + context = file["content"] else: if hybrid_search: context = query_collection_with_hybrid_search( @@ -290,7 +290,7 @@ def get_rag_context( context = None if context: - relevant_contexts.append({**context, "source": doc}) + relevant_contexts.append({**context, "source": file}) extracted_collections.extend(collection_names)