Skip to content

🔎 feat: Add a Single-Owner Presence Check for Embedded Files - #336

Open
berry-13 wants to merge 2 commits into
LibreChat-AI:mainfrom
berry-13:feat/entity-scoped-query
Open

berry-13 wants to merge 2 commits into
LibreChat-AI:mainfrom
berry-13:feat/entity-scoped-query

Conversation

@berry-13

Copy link
Copy Markdown
Contributor

Summary

LibreChat needs to know whether a file is already embedded for an agent before embedding it again (LibreChat-AI/LibreChat#17206). No route can answer that today. /query and /documents read the caller and the entity_id together, so a copy the user embedded under their own id answers for the agent, and with enough of those chunks ranking first the agent's own never reach the top k.

POST /exists takes file_ids and an optional entity_id and returns the ids holding chunks owned by exactly that entity, or by the caller when none is named. It reuses the scoped get_filtered_ids on both stores, runs no embedding and returns no content. A named entity replaces the caller instead of widening the set, so the route only narrows what the same request could already read through /query. The README's retrieval scope section documents it.

Change Type

  • New feature (non-breaking change which adds functionality)

Testing

  • pytest tests/test_authorization.py: 17 passed, including new cases for an entity whose file id the caller also holds, the caller-only scope (a foreign file reads as absent), and an unauthenticated deployment.
  • Negative control: with the route on resolve_scope, the entity case fails because the caller's copy answers for the agent.
  • Full unit suite: 312 passed. Black 24.4.0 is clean on the touched files.
  • The pgvector integration suite was not run locally (needs Docker); get_filtered_ids itself is unchanged and covered there.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have added tests that prove my feature works
  • Local unit tests pass with my changes
  • I have updated the documentation

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-18T09:28:08.318516Z 1fb7404 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 89668bc33a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app/routes/document_routes.py Outdated
executor=request.app.state.thread_pool,
)
else:
found = vector_store.get_filtered_ids(body.file_ids, owners=scope.owners)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Offload Atlas existence lookups from the event loop

When VECTOR_DB_TYPE=atlas-mongo, this branch calls AtlasMongoVector.get_filtered_ids synchronously; that method executes the blocking PyMongo collection.distinct operation (app/services/vector_store/atlas_mongo_vector.py:79-86), so Mongo/network latency here stalls the FastAPI event-loop thread and unrelated concurrent requests. Run this lookup through run_in_executor, as the other non-PG query branches do.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 1fb7404: the synchronous branch now dispatches get_filtered_ids through run_in_executor on the app thread pool, as /query does. test_sync_store_presence_check_leaves_event_loop_responsive asserts the lookup runs on a worker thread while the loop stays free; it fails with the direct call restored.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant