gabykim commited on
Commit
3e469b9
·
1 Parent(s): a479f1f

fallback to intial top_k upon reranking failure

Browse files
src/know_lang_bot/chat_bot/chat_graph.py CHANGED
@@ -229,6 +229,7 @@ class RetrieveContextNode(BaseNode[ChatGraphState, ChatGraphDeps, ChatResult]):
229
  key=lambda x: x[1]
230
  )[:ctx.deps.config.reranker.top_k]
231
  logfire.info('top k embedding search results: {results}', results=top_k_initial)
 
232
 
233
  # Only proceed to reranking if we have initial results
234
  if not initial_chunks:
@@ -267,7 +268,7 @@ class RetrieveContextNode(BaseNode[ChatGraphState, ChatGraphDeps, ChatResult]):
267
  # Fallback to distance-based filtering if reranking fails
268
  LOG.error(f"Reranking failed, falling back to distance-based filtering: {e}")
269
  relevant_chunks, relevant_metadatas = self._filter_by_distance(
270
- chunks=initial_chunks,
271
  metadatas=initial_metadatas,
272
  distances=distances,
273
  threshold=ctx.deps.config.chat.similarity_threshold
 
229
  key=lambda x: x[1]
230
  )[:ctx.deps.config.reranker.top_k]
231
  logfire.info('top k embedding search results: {results}', results=top_k_initial)
232
+ top_k_initial_chunks = [chunk for chunk, _ in top_k_initial]
233
 
234
  # Only proceed to reranking if we have initial results
235
  if not initial_chunks:
 
268
  # Fallback to distance-based filtering if reranking fails
269
  LOG.error(f"Reranking failed, falling back to distance-based filtering: {e}")
270
  relevant_chunks, relevant_metadatas = self._filter_by_distance(
271
+ chunks=top_k_initial_chunks,
272
  metadatas=initial_metadatas,
273
  distances=distances,
274
  threshold=ctx.deps.config.chat.similarity_threshold
src/know_lang_bot/config.py CHANGED
@@ -161,7 +161,7 @@ class RerankerConfig(BaseSettings):
161
  description="API key for the model provider"
162
  )
163
  top_k: int = Field(
164
- default=5,
165
  description="Number of most relevant documents to return from reranking"
166
  )
167
  relevance_threshold: float = Field(
 
161
  description="API key for the model provider"
162
  )
163
  top_k: int = Field(
164
+ default=4,
165
  description="Number of most relevant documents to return from reranking"
166
  )
167
  relevance_threshold: float = Field(