gzdaniel commited on
Commit
ae607b6
·
1 Parent(s): 246c6dd

Improve naive query context format

Browse files
Files changed (1) hide show
  1. lightrag/operate.py +4 -4
lightrag/operate.py CHANGED
@@ -1247,7 +1247,7 @@ async def mix_kg_vector_query(
1247
  # Include time information in content
1248
  formatted_chunks = []
1249
  for c in maybe_trun_chunks:
1250
- chunk_text = "File path: " + c["file_path"] + "\n" + c["content"]
1251
  if c["created_at"]:
1252
  chunk_text = f"[Created at: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(c['created_at']))}]\n{chunk_text}"
1253
  formatted_chunks.append(chunk_text)
@@ -1255,7 +1255,7 @@ async def mix_kg_vector_query(
1255
  logger.debug(
1256
  f"Truncate chunks from {len(valid_chunks)} to {len(formatted_chunks)} (max tokens:{query_param.max_token_for_text_unit})"
1257
  )
1258
- return "\n\n--New Chunk--\n".join(formatted_chunks)
1259
  except Exception as e:
1260
  logger.error(f"Error in get_vector_context: {e}")
1261
  return None
@@ -2074,9 +2074,9 @@ async def naive_query(
2074
  f"Naive query: {len(maybe_trun_chunks)} chunks, top_k: {query_param.top_k}"
2075
  )
2076
 
2077
- section = "\n\n--New Chunk--\n".join(
2078
  [
2079
- "File path: " + c["file_path"] + "\n" + c["content"]
2080
  for c in maybe_trun_chunks
2081
  ]
2082
  )
 
1247
  # Include time information in content
1248
  formatted_chunks = []
1249
  for c in maybe_trun_chunks:
1250
+ chunk_text = "File path: " + c["file_path"] + "\r\n\r\n" + c["content"]
1251
  if c["created_at"]:
1252
  chunk_text = f"[Created at: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(c['created_at']))}]\n{chunk_text}"
1253
  formatted_chunks.append(chunk_text)
 
1255
  logger.debug(
1256
  f"Truncate chunks from {len(valid_chunks)} to {len(formatted_chunks)} (max tokens:{query_param.max_token_for_text_unit})"
1257
  )
1258
+ return "\r\n\r\n--New Chunk--\r\n\r\n".join(formatted_chunks)
1259
  except Exception as e:
1260
  logger.error(f"Error in get_vector_context: {e}")
1261
  return None
 
2074
  f"Naive query: {len(maybe_trun_chunks)} chunks, top_k: {query_param.top_k}"
2075
  )
2076
 
2077
+ section = "\r\n\r\n--New Chunk--\r\n\r\n".join(
2078
  [
2079
+ "File path: " + c["file_path"] + "\r\n\r\n" + c["content"]
2080
  for c in maybe_trun_chunks
2081
  ]
2082
  )