Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

feat: implement automatic RAG indexing for scheduled document processing

LearningCircuit7db17a2e52db
diff --git a/src/local_deep_research/news/subscription_manager/scheduler.py b/src/local_deep_research/news/subscription_manager/scheduler.py
index b0093673b4..08cc0451de 100644
--- a/src/local_deep_research/news/subscription_manager/scheduler.py
+++ b/src/local_deep_research/news/subscription_manager/scheduler.py
@@ -14,6 +14,11 @@ from local_deep_research.settings.logger import log_settings
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.jobstores.base import JobLookupError
+# RAG indexing imports
+from ...research_library.services.library_rag_service import LibraryRAGService
+from ...database.library_init import get_default_library_id
+from ...database.models.library import Document, DocumentCollection
+
SCHEDULER_AVAILABLE = True # Always available since it's a required dependency
@@ -713,15 +718,106 @@ class NewsScheduler:
)
if generate_rag:
- # NOTE: RAG generation is not yet implemented for scheduled document processing
- # RAG embeddings are currently handled automatically when documents are added
- # to the library through the regular upload flow.
- # TODO: Implement scheduled RAG generation for research documents
- logger.warning(
- f"[DOC_SCHEDULER] RAG generation requested for research {research.id} "
- f"but this feature is not yet implemented. RAG embeddings will need to be "
- f"generated manually through the library interface."
+ logger.info(
+ f"[DOC_SCHEDULER] Generating RAG embeddings for research {research.id}"
)
+ try:
+ # Get embedding settings from user configuration
+ embedding_model = settings_manager.get_setting(
+ "local_search_embedding_model",
+ "all-MiniLM-L6-v2",
+ )
+ embedding_provider = (
+ settings_manager.get_setting(
+ "local_search_embedding_provider",
+ "sentence_transformers",
+ )
+ )
+ chunk_size = int(
+ settings_manager.get_setting(
+ "local_search_chunk_size", 1000
+ )
+ )
+ chunk_overlap = int(
+ settings_manager.get_setting(
+ "local_search_chunk_overlap", 200
+ )
+ )
+
+ # Initialize RAG service with user's embedding configuration
+ rag_service = LibraryRAGService(
+ username=username,
+ embedding_model=embedding_model,
+ embedding_provider=embedding_provider,
+ chunk_size=chunk_size,
+ chunk_overlap=chunk_overlap,
+ )
+
+ # Get default Library collection ID
+ library_collection_id = get_default_library_id(
+ username
+ )
+
+ # Query for unindexed documents from this research session
+ documents_to_index = (
+ db.query(Document.id, Document.title)
+ .outerjoin(
+ DocumentCollection,
+ (
+ DocumentCollection.document_id
+ == Document.id
+ )
+ & (
+ DocumentCollection.collection_id
+ == library_collection_id
+ ),
+ )
+ .filter(
+ Document.research_id == research.id,
+ Document.text_content.isnot(None),
+ (
+ DocumentCollection.indexed.is_(
+ False
+ )
+ | DocumentCollection.id.is_(None)
+ ),
+ )
+ .all()
+ )
+
+ if not documents_to_index:
+ logger.info(
+ f"[DOC_SCHEDULER] No unindexed documents found for research {research.id}"
+ )
+ else:
+ # Index each document
+ indexed_count = 0
+ for doc_id, doc_title in documents_to_index:
+ try:
+ result = rag_service.index_document(
+ document_id=doc_id,
+ collection_id=library_collection_id,
+ force_reindex=False,
+ )
+ if result["status"] == "success":
+ indexed_count += 1
+ logger.info(
+ f"[DOC_SCHEDULER] Indexed document {doc_id} ({doc_title}) "
+ f"with {result.get('chunk_count', 0)} chunks"
+ )
+ except Exception as doc_error:
+ logger.exception(
+ f"[DOC_SCHEDULER] Failed to index document {doc_id}: {doc_error}"
+ )
+
+ logger.info(
+ f"[DOC_SCHEDULER] RAG indexing completed for research {research.id}: "
+ f"{indexed_count}/{len(documents_to_index)} documents indexed"
+ )
+ except Exception as e:
+ logger.exception(
+ f"[DOC_SCHEDULER] Failed to generate RAG embeddings for research {research.id}: {e}"
+ )
processed_count += 1
logger.debug(