feat: backend-agnostic vector-sync gauges (pending/documents/chunks)
The only queue metric, mcp_vector_sync_queue_size, was updated inline by the single-user consumer (processor_task) but never by the multi-user consumer (oauth_processor_task). On multi-user tenants (e.g. blackbox-demo, 5 users) the gauge read 0 for 24h while the live anyio buffer held ~2214 pending documents (shown by /api/v1/vector-sync/status). The "indexed" figure was also a chunk count (16039 points ≈ 480 docs) mislabelled as documents. Publish a consumer-independent snapshot from a periodic task (vector/metrics_publisher.vector_sync_metrics_task), spawned in BOTH lifespan task groups (single-user and multi-user) and every queue backend: - mcp_vector_sync_pending_documents — outstanding work via ingest_status.get_ingest_pending() (anyio buffer depth or procrastinate todo+doing); also keeps the legacy queue_size gauge meaningful on all paths. - mcp_vector_sync_indexed_documents — distinct documents, counted exactly and cheaply via the one chunk_index=0 point per document (no facet). - mcp_vector_sync_indexed_chunks — total non-placeholder points. The /api/v1/vector-sync/status endpoint now returns indexed_documents (distinct docs) AND indexed_chunks separately, so documents and chunks are no longer conflated. The publisher uses approximate Qdrant counts (every-N-seconds gauge); the on-demand endpoint counts exactly. New knob: VECTOR_SYNC_METRICS_REFRESH_INTERVAL (default 20s). Fail-safe: a metrics refresh never disturbs ingest. BREAKING CHANGE: /api/v1/vector-sync/status field `indexed_documents` now holds the distinct-document count (was the chunk count); the chunk count moved to the new `indexed_chunks` field. The Astrolabe UI + the nc_get_vector_sync_status MCP tool / userinfo page are harmonized in a follow-up (Deck #195). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
55ea8dd358
commit
fbe70ecd9c
@@ -166,6 +166,30 @@ vector_sync_queue_size = Gauge(
|
||||
"Current number of documents in processing queue",
|
||||
)
|
||||
|
||||
# Outstanding ingest work (queued + in-flight), backend-agnostic. Published by
|
||||
# the periodic vector_sync_metrics_task from ingest_status.get_ingest_pending(),
|
||||
# so it is correct on every consumer path (single-user processor_task AND
|
||||
# multi-user oauth_processor_task) and every queue backend (anyio buffer depth
|
||||
# or procrastinate todo+doing) — unlike the per-loop update of
|
||||
# ``vector_sync_queue_size``, which only ran on the single-user path.
|
||||
vector_sync_pending_documents = Gauge(
|
||||
"mcp_vector_sync_pending_documents",
|
||||
"Outstanding ingest documents (queued or in-flight, not yet processed)",
|
||||
)
|
||||
|
||||
# Corpus size in the vector store. ``indexed_documents`` counts distinct
|
||||
# documents (one chunk_index=0 point per document); ``indexed_chunks`` counts
|
||||
# every non-placeholder point. The two differ by the chunk fan-out (~N chunks
|
||||
# per document), which is why a single "indexed" figure is ambiguous.
|
||||
vector_sync_indexed_documents = Gauge(
|
||||
"mcp_vector_sync_indexed_documents",
|
||||
"Distinct documents indexed in the vector store (non-placeholder)",
|
||||
)
|
||||
vector_sync_indexed_chunks = Gauge(
|
||||
"mcp_vector_sync_indexed_chunks",
|
||||
"Total indexed chunks (non-placeholder points) in the vector store",
|
||||
)
|
||||
|
||||
qdrant_operations_total = Counter(
|
||||
"mcp_qdrant_operations_total",
|
||||
"Total Qdrant vector database operations",
|
||||
@@ -520,6 +544,21 @@ def update_vector_sync_queue_size(size: int) -> None:
|
||||
vector_sync_queue_size.set(size)
|
||||
|
||||
|
||||
def update_vector_sync_pending_documents(count: int) -> None:
|
||||
"""Set the outstanding-ingest-work gauge (queued + in-flight documents)."""
|
||||
vector_sync_pending_documents.set(count)
|
||||
|
||||
|
||||
def update_vector_sync_indexed_documents(count: int) -> None:
|
||||
"""Set the distinct-indexed-documents gauge."""
|
||||
vector_sync_indexed_documents.set(count)
|
||||
|
||||
|
||||
def update_vector_sync_indexed_chunks(count: int) -> None:
|
||||
"""Set the total-indexed-chunks gauge."""
|
||||
vector_sync_indexed_chunks.set(count)
|
||||
|
||||
|
||||
def record_document_parse(
|
||||
processor: str,
|
||||
tier: str,
|
||||
|
||||
Reference in New Issue
Block a user