Skip to content
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
59ab231
fix(indexing): delete vectors before catalog rows
hedhoud Jul 15, 2026
1fdf372
test(partitions): align fake vector filtering
hedhoud Jul 15, 2026
5690178
test(partitions): remove redundant async markers
hedhoud Jul 16, 2026
cde6acb
fix(indexing): close delete cleanup races
hedhoud Jul 16, 2026
4456337
fix(indexing): scope race cleanup to indexing task
hedhoud Jul 16, 2026
289230a
fix(indexing): wait for cancellable task refs
hedhoud Jul 16, 2026
1cc71ff
fix(indexing): wait for cancelled tasks to settle
hedhoud Jul 16, 2026
5c54207
fix(indexing): preserve legacy ingest and stale task cleanup
hedhoud Jul 16, 2026
7f2217b
fix(indexing): address delete cleanup review races
hedhoud Jul 16, 2026
b8ebe65
fix(indexing): accept terminal ref registration states
hedhoud Jul 16, 2026
927b0c9
fix(indexing): surface post-delete cleanup failures
hedhoud Jul 16, 2026
4462d7c
fix(indexing): fail closed during task cancellation
hedhoud Jul 16, 2026
fa726f7
fix(indexing): preserve cache and task markers
hedhoud Jul 16, 2026
2f1fcc8
fix(indexing): close vector cleanup review gaps
hedhoud Jul 16, 2026
fbac962
fix(indexing): block detail-less active tasks on delete
hedhoud Jul 16, 2026
03c0395
fix(indexing): restore direct replace cleanup
hedhoud Jul 17, 2026
f8f6457
fix(indexing): clarify partition policy metadata helpers
hedhoud Jul 17, 2026
ac1455c
fix(indexing): tolerate legacy indexer actors
hedhoud Jul 20, 2026
8daf6a2
Merge remote-tracking branch 'origin/develop' into pr-671
hedhoud Jul 20, 2026
6fc790a
fix(indexing): fence partition deletes against uploads
hedhoud Jul 20, 2026
c9e0366
fix(indexing): fence file deletes against uploads
hedhoud Jul 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions openrag/core/indexing/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ async def dispatch_indexing(
replace: bool,
indexation_config: dict | None = None,
embedder_name: str | None = None,
require_existing_partition: bool = False,
allow_legacy_require_existing_partition_retry: bool = False,
) -> str:
"""Queue an (re)indexing job, register its task state, return its id."""
...
Expand Down
10 changes: 10 additions & 0 deletions openrag/core/utils/conts.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@
IMG_WRAPPER_CLOSE = "\n\n</image_description>"

IMAGE_PLACEHOLDER = f"""{IMG_WRAPPER_OPEN}[Image Placeholder]{IMG_WRAPPER_CLOSE}"""

INTERNAL_METADATA_PREFIX = "_openrag"


def is_internal_metadata_key(key: object) -> bool:
return isinstance(key, str) and key.startswith(INTERNAL_METADATA_PREFIX)


def strip_internal_metadata(row: dict) -> dict:
return {key: value for key, value in row.items() if not is_internal_metadata_key(key)}
5 changes: 5 additions & 0 deletions openrag/core/vector_stores/vector_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ async def delete(self, ids: list[str], collection: str = "default") -> int:
"""Delete chunks by ID. Returns count of deleted items."""
...

@abstractmethod
async def delete_by_filter(self, filters: dict[str, Any]) -> int:
"""Delete chunks matching the given filter expression. Returns count."""
...

@abstractmethod
async def ensure_collection(self, name: str, dimension: int, **kwargs: Any) -> None:
"""Create collection if it doesn't exist."""
Expand Down
2 changes: 2 additions & 0 deletions openrag/di/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ def partition_service(self) -> PartitionService:
"""PartitionService — lazily built, cached for the container's lifetime."""
if self._partition_service is None:
from services.orchestrators.partition_service import PartitionService
from services.workers.bootstrap import get_task_state_manager

settings = self._require_settings()
self._partition_service = PartitionService(
Expand All @@ -413,6 +414,7 @@ def partition_service(self) -> PartitionService:
user_repo=self.user_repo,
collection=settings.vectordb.collection_name,
config=settings,
task_state_manager_factory=get_task_state_manager,
)
return self._partition_service

Expand Down
9 changes: 8 additions & 1 deletion openrag/services/orchestrators/conversion_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

from typing import TYPE_CHECKING

from core.utils.conts import is_internal_metadata_key
from core.utils.logging import get_logger
from core.utils.text import sanitize_extracted_text

Expand Down Expand Up @@ -87,8 +88,14 @@ async def get_chunk(self, chunk_id: str) -> dict | None:
row = rows[0]
return {
"page_content": row["text"],
"metadata": {k: v for k, v in row.items() if k not in ("text", "vector")},
"metadata": _public_chunk_metadata(row),
}


__all__ = ["ConversionService"]


def _public_chunk_metadata(row: dict) -> dict:
return {
key: value for key, value in row.items() if key not in ("text", "vector") and not is_internal_metadata_key(key)
}
45 changes: 33 additions & 12 deletions openrag/services/orchestrators/indexing_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

from __future__ import annotations

from collections.abc import AsyncIterator
from contextlib import asynccontextmanager
from pathlib import Path
from typing import TYPE_CHECKING, Any

Expand Down Expand Up @@ -117,6 +119,20 @@ def _partition_configs(self) -> dict[str, Any]:
return {}
return getattr(self._config, "partitions", {}) or {}

@asynccontextmanager
async def _partition_admission(self, partition: str) -> AsyncIterator[bool]:
if self._partition_service is None:
yield False
return

admission = getattr(self._partition_service, "indexing_admission", None)
if admission is not None:
async with admission(partition) as partition_existed:
yield bool(partition_existed)
return

yield await self._partition_service.partition_exists(partition)

async def _ensure_editor_access_after_create_race(self, partition: str, user: dict | None) -> None:
if user is None:
return
Expand Down Expand Up @@ -196,18 +212,23 @@ async def add_file(
sanitized_filename=sanitized_filename,
original_filename=original_filename,
)
await self._ensure_partition_exists(partition, user)
indexation_config, embedder_name = self._resolve_indexation_dispatch_config(partition)
return await self._dispatcher.dispatch_indexing(
path=file_path,
metadata=full_metadata,
partition=partition,
user=user,
workspace_ids=workspace_ids,
replace=replace,
indexation_config=indexation_config,
embedder_name=embedder_name,
)
async with self._partition_admission(partition) as partition_existed_at_admission:
await self._ensure_partition_exists(partition, user)
require_existing_partition = bool(self._partition_configs()) or partition_existed_at_admission
indexation_config, embedder_name = self._resolve_indexation_dispatch_config(partition)
legacy_actor_preserves_partition_guard = require_existing_partition and indexation_config is not None
return await self._dispatcher.dispatch_indexing(
path=file_path,
metadata=full_metadata,
partition=partition,
user=user,
workspace_ids=workspace_ids,
replace=replace,
indexation_config=indexation_config,
embedder_name=embedder_name,
require_existing_partition=require_existing_partition,
allow_legacy_require_existing_partition_retry=legacy_actor_preserves_partition_guard,
)

async def delete_file(self, file_id: str, partition: str) -> None:
await self._dispatcher.delete_file(file_id, partition)
Expand Down
11 changes: 8 additions & 3 deletions openrag/services/orchestrators/mcp_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from urllib.parse import urljoin, urlparse

import httpx
from core.utils.conts import is_internal_metadata_key
from core.utils.exceptions import ValidationError
from core.utils.log_tail import collect_task_logs
from core.utils.logging import get_logger
Expand Down Expand Up @@ -251,7 +252,7 @@ def _shape_chunk(chunk: Any) -> dict[str, Any]:
return {
"chunk_id": meta.get("_id") or chunk.id,
"content": chunk.text,
"metadata": meta,
"metadata": _public_chunk_metadata(meta, exclude=("_id",)),
}

# ------------------------------------------------------------------
Expand Down Expand Up @@ -296,7 +297,7 @@ async def get_file_info(
{"partition": partition, "file_id": file_id},
output_fields=["*"],
)
metadata = {k: v for k, v in rows[0].items() if k not in ("_id", "text", "vector")} if rows else {}
metadata = _public_chunk_metadata(rows[0], exclude=("_id", "text", "vector")) if rows else {}
return {
"partition": partition,
"file_id": file_id,
Expand Down Expand Up @@ -344,7 +345,7 @@ async def get_file_chunks(
{
"chunk_id": row.get("_id"),
"content": row.get("text"),
"metadata": {k: v for k, v in row.items() if k not in ("text", "_id", "vector")},
"metadata": _public_chunk_metadata(row, exclude=("text", "_id", "vector")),
}
for row in page
],
Expand Down Expand Up @@ -694,3 +695,7 @@ async def _safe_download(self, url: str, dest: Path) -> None:


__all__ = ["MCPService"]


def _public_chunk_metadata(row: dict[str, Any], *, exclude: tuple[str, ...]) -> dict[str, Any]:
return {key: value for key, value in row.items() if key not in exclude and not is_internal_metadata_key(key)}
Loading
Loading