Skip to content

Python: Prefer injected Qdrant clients over connection settings - #9993

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 2 commits into
microsoft:mainfrom
ZedingZhang:cursor/qdrant-injected-client-settings-8c19
Nov 3, 2026
Merged

Eduard van Valkenburg (eavanvalkenburg) merged 2 commits into
microsoft:mainfrom
ZedingZhang:cursor/qdrant-injected-client-settings-8c19

Conversation

@ZedingZhang

@ZedingZhang ZedingZhang (ZedingZhang) commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Motivation & Context

QdrantStore and QdrantCollection raise ValueError when an injected AsyncQdrantClient is supplied alongside URL, API-key, or .env options. They also honor managed_client=True by closing that caller-supplied client. Applications cannot reuse a configured client together with shared constructor options, and cleanup can close a client the caller still owns.

Description & Review Guide

  • What are the major changes? Resolve an injected client before connection settings. Skip URL, API-key, and .env loading for that client, and always leave it caller-owned, including when managed_client=True. Update the constructor documentation, README, and the settings and ownership tests.
  • What is the impact of these changes? Redundant, empty, or invalid connection settings no longer reject or affect an injected client. Store and collection cleanup no longer closes it. Connector-created clients still follow explicit arguments, then environment settings, then SDK defaults, and they still close by default. Collection schema and operation options are unchanged.
  • What do you want reviewers to focus on? Tests cover both constructors, confirm load_settings and AsyncQdrantClient are not called for an injected client, and confirm cleanup leaves that client open. The regression fails on the original implementation and passes with the fix.

Related Issue

Fixes #9957. The issue has the ready-for-implementation label; no competing open PR was found before submission.

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details: An AI coding assistant helped with investigation, implementation, tests, documentation, and this PR description. I review the submitted content and take responsibility for it.

Contribution Checklist

  • The code builds clean without any errors or warnings — Qdrant sdist and wheel built successfully.
  • All unit tests pass, and I have added new tests where possible — Qdrant unit suite: 268 passed, 84 integration tests deselected. Ruff formatting/lint, strict source Pyright, and all five test type checkers pass. No live Qdrant integration tests were run.
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

An injected AsyncQdrantClient now takes precedence over URL, API key, and
.env options. Those settings are not read, and the caller keeps ownership
even when managed_client is true.

Fixes microsoft#9957

Co-authored-by: ZedingZhang <me@zedingzhang.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The constructor creates an SDK client before validating collection arguments, leaking the client when validation fails; initialization must be reordered and covered by a regression test.

1 open issue
What changed in this PR

This PR addresses #9957 by making injected Qdrant clients take precedence over connection settings and remain caller-owned in the Python connector.

Changes:

  • Centralizes client resolution for stores and collections, bypassing connection settings for injected clients.
  • Expands regression tests for settings precedence and ownership, and updates test cleanup.
  • Documents the revised client lifecycle behavior.
File Description
python/​packages/​qdrant/​tests/​qdrant/​test_settings.py Tests ignored settings, factory bypass, and shared-client ownership.
python/​packages/​qdrant/​tests/​qdrant/​test_collection.py Updates ownership assertions and explicitly closes caller-owned test clients.
python/​packages/​qdrant/​tests/​qdrant/​conftest.py Adds explicit cleanup for the injected integration-test client.
python/​packages/​qdrant/​README.md Documents injected-client precedence and caller ownership.
python/​packages/​qdrant/​agent_framework_qdrant/​_vector_store.py Adds shared client resolution and updates constructor documentation.

Review effort: Balanced

QdrantCollection now runs base initialization before resolving a client, so
invalid collection arguments raise without calling the SDK factory.

Co-authored-by: ZedingZhang <me@zedingzhang.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the injected Qdrant client precedence and caller-ownership changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Merged via the queue into microsoft:main with commit d615566 Nov 3, 2026
51 checks passed

This branch was previously deployed

1 inactive deployment
github-app-auth — 61109187 Deployed Nov 2, 2026 by cursor[bot] via add_label #26889
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: Qdrant injected clients do not take precedence over settings and lifecycle

3 participants