DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
fix: prevent Document nodes from bypassing chunking pipeline (#509)
washi45c0af9983ab8
diff --git a/deeptutor/services/rag/pipelines/llamaindex/ingestion.py b/deeptutor/services/rag/pipelines/llamaindex/ingestion.pyindex 774b2e9a6..820de00ee 100644--- a/deeptutor/services/rag/pipelines/llamaindex/ingestion.py+++ b/deeptutor/services/rag/pipelines/llamaindex/ingestion.py@@ -12,7 +12,7 @@ from typing import Anyfrom llama_index.core import Settings, VectorStoreIndexfrom llama_index.core.ingestion import IngestionPipelinefrom llama_index.core.node_parser import SentenceSplitter-from llama_index.core.schema import BaseNode+from llama_index.core.schema import BaseNode, Documentdef build_ingestion_pipeline() -> IngestionPipeline:@@ -34,14 +34,29 @@ def build_ingestion_pipeline() -> IngestionPipeline:)+def _has_precomputed_embedding(node: Any) -> bool:+ """Return True if node already carries an embedding vector.++ LlamaIndex's Document class inherits from BaseNode, so a naive+ ``isinstance(doc, BaseNode)`` check incorrectly classifies every+ Document as pre-embedded, bypassing the chunking pipeline entirely.+ This helper distinguishes genuinely pre-embedded nodes (e.g. ImageNode+ produced by multimodal loaders) from regular Documents that still need+ splitting and embedding.+ """+ if isinstance(node, Document):+ return False+ return isinstance(node, BaseNode) and bool(getattr(node, "embedding", None))++def documents_to_nodes(documents: list[Any], *, show_progress: bool = True) -> list[Any]:"""Convert LlamaIndex documents into embedded nodes.Pre-embedded nodes, such as ImageNode instances produced by the documentloader, pass through unchanged so they are not re-embedded as text."""- text_documents = [document for document in documents if not isinstance(document, BaseNode)]- preembedded_nodes = [document for document in documents if isinstance(document, BaseNode)]+ text_documents = [doc for doc in documents if not _has_precomputed_embedding(doc)]+ preembedded_nodes = [doc for doc in documents if _has_precomputed_embedding(doc)]nodes: list[Any] = []if text_documents: