srilakshu012456 commited on
Commit
315de21
·
verified ·
1 Parent(s): 8bc4493

Update services/kb_creation.py

Browse files
Files changed (1) hide show
  1. services/kb_creation.py +10 -9
services/kb_creation.py CHANGED
@@ -93,19 +93,20 @@ def _split_by_sections(doc: Document) -> List[Tuple[str, List[str]]]:
93
 
94
  def _chunk_text_with_context(doc_title: str, section_title: str, paragraphs: List[str], max_words: int = 900) -> List[str]:
95
  """
96
- Build chunks that keep: Document Title + Section Title + paragraphs,
97
- so short bullets like 'Putaway error: ...' stay with their header.
98
  """
99
- # Join paras for chunking
100
- body = "\n".join(paragraphs)
 
101
  words = body.split()
102
  chunks: List[str] = []
103
  for i in range(0, len(words), max_words):
104
- chunk_body = ' '.join(words[i:i + max_words])
105
- chunk_text = f"{doc_title}\n{section_title}\n\n{chunk_body}".strip()
106
- chunks.append(chunk_text)
107
- if not chunks and body:
108
- chunks = [f"{doc_title}\n{section_title}\n\n{body}"]
109
  return chunks
110
 
111
  # ------------------------- Ingestion ------------------------------
 
93
 
94
  def _chunk_text_with_context(doc_title: str, section_title: str, paragraphs: List[str], max_words: int = 900) -> List[str]:
95
  """
96
+ Build chunks from paragraphs ONLY (no doc/section headers in the text).
97
+ We still keep title/section inside metadata so retrieval quality remains high.
98
  """
99
+ body = "\n".join(paragraphs).strip()
100
+ if not body:
101
+ return []
102
  words = body.split()
103
  chunks: List[str] = []
104
  for i in range(0, len(words), max_words):
105
+ chunk_body = ' '.join(words[i:i + max_words]).strip()
106
+ if chunk_body:
107
+ chunks.append(chunk_body) # <-- no headers inside the chunk content
108
+ if not chunks:
109
+ chunks = [body]
110
  return chunks
111
 
112
  # ------------------------- Ingestion ------------------------------