Skip to content

Commit 0111c2c

Browse files
committed
catch an error when trying to extract source nodes from responses
1 parent 9cbc1a1 commit 0111c2c

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

llm-service/app/services/chat/chat.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
# BUSINESS ADVANTAGE OR UNAVAILABILITY, OR LOSS OR CORRUPTION OF
3636
# DATA.
3737
#
38+
import logging
3839
import re
3940
import time
4041
import uuid
@@ -59,6 +60,7 @@
5960
from app.services.query import querier
6061
from app.services.query.query_configuration import QueryConfiguration
6162

63+
logger = logging.getLogger(__name__)
6264

6365
def chat(
6466
session: Session,
@@ -187,18 +189,21 @@ def extract_nodes_from_response_str(
187189
extracted_node_ids = [
188190
node_id for node_id in extracted_node_ids if node_id not in node_ids_present
189191
]
190-
if extracted_node_ids:
191-
qdrant_store = VectorStoreFactory.for_chunks(data_source_id)
192-
vector_store = qdrant_store.llama_vector_store()
193-
extracted_source_nodes = vector_store.get_nodes(node_ids=extracted_node_ids)
194-
195-
# cast them into NodeWithScore with score 0.0
196-
extracted_source_nodes_w_score = [
197-
NodeWithScore(node=node, score=0.0) for node in extracted_source_nodes
198-
]
199-
# add the source nodes to the response
200-
chat_response.source_nodes += extracted_source_nodes_w_score
201-
192+
if len(extracted_node_ids) > 0:
193+
try:
194+
qdrant_store = VectorStoreFactory.for_chunks(data_source_id)
195+
vector_store = qdrant_store.llama_vector_store()
196+
extracted_source_nodes = vector_store.get_nodes(node_ids=extracted_node_ids)
197+
198+
# cast them into NodeWithScore with score 0.0
199+
extracted_source_nodes_w_score = [
200+
NodeWithScore(node=node, score=0.0) for node in extracted_source_nodes
201+
]
202+
# add the source nodes to the response
203+
chat_response.source_nodes += extracted_source_nodes_w_score
204+
except Exception as e:
205+
logger.warning("Failed to extract nodes from response citations (%s): %s", extracted_node_ids, e)
206+
pass
202207
return chat_response
203208

204209

llm-service/app/services/query/tasks/retriever.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@
4646

4747

4848
class RetrieverResult(BaseModel):
49-
node_id: str | None = None
50-
score: float | None = None
51-
content: str | None = None
49+
node_id: str
50+
score: float
51+
content: str
5252

5353

5454
class RetrieverOutput(BaseModel):
@@ -68,7 +68,7 @@ def build_retriever_task(
6868
description="Retrieve relevant information from the index based on the user's question.\n\n"
6969
f"<Chat history>:\n{chat_history}\n\n<Question>:\n{query}\n\n"
7070
"If the question can be answered using the chat history or the context, do not use the retriever tool and "
71-
"return blank strings for the retriever results. If needed, use the chat history to refine the user's question "
71+
"return blank strings for the node_id and content, and 0 for the score. If needed, use the chat history to refine the user's question "
7272
"to pass as input to the retriever tool.",
7373
agent=agent,
7474
tools=[retriever_tool],

llm-service/app/services/query/tasks/search.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646

4747

4848
class SearchResult(BaseModel):
49-
result: str | None = None
50-
link: str | None = None
49+
result: str
50+
link: str
5151

5252

5353
class SearchOutput(BaseModel):

0 commit comments

Comments
 (0)