feat: dedup shared-file parsing/embedding across users in vector sync
A file shared across many users — directly, or via a group folder shared to a group — was parsed and embedded once per user. Chunk point IDs are user-agnostic (uuid5(tenant_id, doc_id=fileid, chunk_index)), but the per-user freshness gate filtered Qdrant by user_id, so two readers ping-ponged: each overwrote the other's points and each kept seeing "not indexed for me", reprocessing every scan. Production telemetry (note 386945, finding #5) measured identical docs re-processed every few hours at 7-13s each, with PDF parse ~62% of per-doc cost. Layer 1 — tenant-wide dedup: - Thread the scanner's tag-REPORT etag into the file DocumentTask and the chunk payload; index `etag` as a KEYWORD field. - vector/sharing_state.find_indexed_content scrolls tenant-wide (no user_id filter) for a non-placeholder point matching (doc_id, doc_type, etag), gated on embedding_identity in Python so a model switch correctly forces a re-embed. - Scanner skips enqueue and the processor skips fetch/parse/embed when a match exists (cross-worker race-guard before WebDAV read). Dedup is fail-safe: a Qdrant error degrades to "process normally". Layer 2 — observed-access ACL (no admin / GroupFolders API needed): - Each point carries `acl_principals` = the set of user:<uid> whose scanner has observed (hence can read) the file. The per-user tag REPORT is the access oracle; group membership/GroupFolders enumeration is admin-only and unavailable in multi-user modes. - build_ownership_filter ORs MatchAny(acl_principals, ["user:<me>"]) so a deduplicated shared/group-folder point surfaces to every reader; verify-on-read (_verify_files) remains the precise ACL gate. - Deletion/eviction become "release one user": drop the principal and delete the points only when the set empties, so one user untagging a shared file doesn't evict it for the others. Legacy points without the field keep the original per-user delete. 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
0919513f21
commit
1c93e7286d
@@ -312,8 +312,12 @@ class TestProcessDocumentMetricCounting:
|
||||
)
|
||||
|
||||
qmock = MagicMock()
|
||||
qmock.delete = AsyncMock()
|
||||
with patch.object(proc, "get_qdrant_client", new=AsyncMock(return_value=qmock)):
|
||||
# Deletion now delegates to release_document_for_user (release-one-user
|
||||
# semantics); stub it so the test exercises only the metric accounting.
|
||||
with (
|
||||
patch.object(proc, "get_qdrant_client", new=AsyncMock(return_value=qmock)),
|
||||
patch.object(proc, "release_document_for_user", new=AsyncMock()),
|
||||
):
|
||||
await proc.process_document(task, MagicMock())
|
||||
|
||||
assert metric_sample(
|
||||
@@ -339,8 +343,16 @@ class TestProcessDocumentMetricCounting:
|
||||
)
|
||||
|
||||
qmock = MagicMock()
|
||||
qmock.delete = AsyncMock(side_effect=RuntimeError("boom"))
|
||||
with patch.object(proc, "get_qdrant_client", new=AsyncMock(return_value=qmock)):
|
||||
# A failed release still counts as a processed (error) delete and must
|
||||
# not touch the indexed counter.
|
||||
with (
|
||||
patch.object(proc, "get_qdrant_client", new=AsyncMock(return_value=qmock)),
|
||||
patch.object(
|
||||
proc,
|
||||
"release_document_for_user",
|
||||
new=AsyncMock(side_effect=RuntimeError("boom")),
|
||||
),
|
||||
):
|
||||
with pytest.raises(RuntimeError):
|
||||
await proc.process_document(task, MagicMock())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user