Spaces:
Sleeping
Sleeping
Update services/kb_creation.py
Browse files- 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
|
| 97 |
-
|
| 98 |
"""
|
| 99 |
-
|
| 100 |
-
|
|
|
|
| 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 |
-
|
| 106 |
-
|
| 107 |
-
if not chunks
|
| 108 |
-
chunks = [
|
| 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 ------------------------------
|