Skip to content

fix(retrieve): call with_tenant on collection before query #8490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

RA1NCS
Copy link

@RA1NCS RA1NCS commented Jul 3, 2025

Summary

Calling multi-tenant hybrid search in WeaviateRM raised
AttributeError: '_QueryCollection' object has no attribute 'with_tenant'.
This PR fixes the bug by scoping the collection first (collection.with_tenant(...)) before executing .query.hybrid(...).

Root cause

The v4 Python client exposes with_tenant() on Collection, not on the
_QueryCollection helper returned by collection.query.
Current code path:

# buggy – AttributeError
collection.query.with_tenant(tenant).hybrid(...)

Fix

# fixed – tenant scoping first, then query
collection.with_tenant(tenant).query.hybrid(...)

How to reproduce the original bug

client = weaviate.connect_to_weaviate_cloud(
    cluster_url=os.environ["WEAVIATE_URL"],
    auth_credentials=Auth.api_key(os.environ["WEAVIATE_API_KEY"]),
)

rm = WeaviateRM(
    weaviate_client=client,
    weaviate_collection_name="test-collection",
    tenant_id="dev",
)

# raises AttributeError on current main
rm("What is the capital of France?")

What’s in this PR

  • Single-line change in dspy/retrieve/weaviate_rm.py (no other files touched).

Test & lint status

Step Result
pre-commit run --all-files ✅ passed
uv run pytest (macOS, Python 3.10) ✅ 402 passed, 222 skipped, 2 xfail
pytest summary
402 passed, 222 skipped, 2 xfailed, 12 warnings in 76.9 s

Checklist

  • Follows Contribution Guide.
  • Only necessary source change; no lockfile or version bumps.
  • Pre-commit hooks clean.
  • Full test suite passes locally.
  • Unit tests added/updated if needed (N/A – existing retrieval tests exercised path).
  • Docs updated (N/A).

Related issues

Notes for reviewers

This unblocks multi-tenant RAG flows with the v4 Weaviate Python client.

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