Skip to content

fix: accept dict-shaped vector params in RestToGrpc converters#1208

Open
wtfashwin wants to merge 1 commit into
qdrant:masterfrom
wtfashwin:fix/issue-1066-vectors-config-dict
Open

fix: accept dict-shaped vector params in RestToGrpc converters#1208
wtfashwin wants to merge 1 commit into
qdrant:masterfrom
wtfashwin:fix/issue-1066-vectors-config-dict

Conversation

@wtfashwin
Copy link
Copy Markdown

Summary

When vectors_config (or sparse_vectors_config, or VectorParamsDiff) is passed as a raw dict — e.g. parsed back from telemetry JSON — the gRPC path fails with AttributeError: 'dict' object has no attribute 'size'. The HTTP path works because pydantic on models.CreateCollection coerces the dict for free, but the gRPC converters access .size / .distance / .modifier directly and assume a fully-validated pydantic model.

This PR coerces dict input to the corresponding pydantic model at the top of three converters so both transports accept the same input shapes:

  • RestToGrpc.convert_vector_params
  • RestToGrpc.convert_vector_params_diff
  • RestToGrpc.convert_sparse_vector_params

Coercing once at the leaf converter is enough — convert_vectors_config / convert_sparse_vector_config / convert_vectors_config_diff all fan out to these.

Fixes #1066

Reproduction (before)

from qdrant_client import QdrantClient

vectors_config = {
    "vector1": {"size": 1024, "distance": "Cosine", "on_disk": True, "datatype": "float16"},
    "vector2": {"size": 1024, "distance": "Cosine", "on_disk": True, "datatype": "float16"},
}
q = QdrantClient(url="http://localhost:6333", prefer_grpc=True)
q.create_collection("foo", vectors_config=vectors_config)
# AttributeError: 'dict' object has no attribute 'size'

After: works on both prefer_grpc=True and the default HTTP path.

Test plan

  • Added 4 unit tests in tests/conversions/test_validate_conversions.py covering the named-vectors dict case, the single-VectorParams dict case, VectorParamsDiff dict, and SparseVectorParams dict — each asserts dict input produces the same gRPC output as the equivalent pydantic-model input.
  • pytest tests/conversions/ -q — 25 passed.
  • mypy qdrant_client/conversions/conversion.py — clean.
  • ruff format --check --line-length=99 qdrant_client/conversions/conversion.py tests/conversions/test_validate_conversions.py — clean.

When a user passes a vectors_config (or sparse_vectors_config, or a
VectorParamsDiff) as a raw dict — e.g. parsed from JSON / telemetry —
the gRPC path raised AttributeError because the per-param converters
expected pydantic models and accessed attributes like `.size` directly.
The HTTP path works since pydantic coerces the dict on its own.

Coerce the dict to the corresponding pydantic model at the top of the
per-param converters so both transports accept the same input shapes.

Fixes qdrant#1066
@netlify
Copy link
Copy Markdown

netlify Bot commented May 18, 2026

Deploy Preview for poetic-froyo-8baba7 ready!

Name Link
🔨 Latest commit 4f807ae
🔍 Latest deploy log https://app.netlify.com/projects/poetic-froyo-8baba7/deploys/6a0b591b7a11180008fc96be
😎 Deploy Preview https://deploy-preview-1208--poetic-froyo-8baba7.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 18, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5a427f16-b3a4-4b7b-aa85-8de61a656983

📥 Commits

Reviewing files that changed from the base of the PR and between 326adef and 4f807ae.

📒 Files selected for processing (2)
  • qdrant_client/conversions/conversion.py
  • tests/conversions/test_validate_conversions.py

📝 Walkthrough

Walkthrough

This PR adds dict input normalization to three RestToGrpc conversion helpers: convert_vector_params, convert_vector_params_diff, and convert_sparse_vector_params. Each method now detects when the input is a plain dict and coerces it into the corresponding REST Pydantic model (VectorParams, VectorParamsDiff, or SparseVectorParams) before proceeding with gRPC message construction. Accompanying test cases verify that dict inputs and equivalent model instances produce identical outputs, covering vector params, named vector configurations, vector param diffs, and sparse vector configurations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: accept dict-shaped vector params in RestToGrpc converters' directly summarizes the main change: enabling the gRPC converters to accept dictionary inputs for vector parameters.
Description check ✅ Passed The description clearly explains the problem (AttributeError when passing dicts to gRPC converters), the solution (coercing dicts to pydantic models), affected converters, and test coverage.
Linked Issues check ✅ Passed The PR directly addresses issue #1066 by coercing dict inputs in the three leaf converters, enabling gRPC path to accept the same dict-shaped vector params as the HTTP path.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing dict coercion in the three specified converters and adding corresponding unit tests; no unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@wtfashwin
Copy link
Copy Markdown
Author

Friendly ping — ready
for review whenever a maintainer has a moment. Targeted fix coercing dict →
pydantic at the three leaf converters (convert_vector_params,
convert_vector_params_diff, convert_sparse_vector_params), matching the
existing isinstance(model, dict) pattern used throughout conversion.py. 4 new
tests added; pytest tests/conversions/ -q passes 25 locally. The 'unstable'
status is only the Netlify docs-preview skipping. Thanks!

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.

Can't convert vector size into gRPC when parsing from JSON

2 participants