fix: improve error messages for unsupported index configurations#141
fix: improve error messages for unsupported index configurations#141Junio243 wants to merge 6 commits intoalibaba:mainfrom
Conversation
Add try-except blocks around CreateIndex and Optimize calls to catch RuntimeError from C++ core and provide more descriptive error messages. This helps users understand when a metric/data type combination is not supported (e.g., cosine metric with INT8 vectors). Fixes alibaba#78
There was a problem hiding this comment.
Pull request overview
This PR improves the Python Collection wrapper’s UX by enriching exceptions coming from the C++ core when index creation or optimization fails due to unsupported configurations (issue #78).
Changes:
- Add contextual error wrapping for
Collection.create_index()failures originating from the C++ core. - Add contextual error wrapping for
Collection.optimize()failures originating from the C++ core. - Update docstrings to document known limitations and newly raised
RuntimeErrors.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
python/zvec/model/collection.py
Outdated
|
|
||
| # Attempt to create the index in the C++ core. If it fails (e.g., due to |
There was a problem hiding this comment.
There are blank lines with trailing indentation whitespace (e.g., around this separator before the try/except). This can cause lint/pre-commit failures and adds noise to diffs; please remove the trailing whitespace on empty lines.
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
|
@copilot open a new pull request to apply changes based on the comments in this thread |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Clean up trailing whitespace on empty lines to pass lint checks.
|
@copilot open a new pull request to apply changes based on the comments in this thread |
1 similar comment
|
@copilot open a new pull request to apply changes based on the comments in this thread |
Problem
Fixes #78
Currently, when users attempt to create indexes with unsupported metric/data type combinations (e.g., cosine metric with INT8 vectors) or call
optimize()on collections with unsupported index configurations, they receive genericRuntimeErrorexceptions from the C++ core with minimal context:Scenario 1: Creating HNSW/IVF/Flat indexes on INT8 vector fields with
MetricType.COSINEfails with:Scenario 2: Calling
collection.optimize()on IVF indexes with cosine metric fails with:These error messages don't explain:
Root Cause
The Python wrapper in
python/zvec/model/collection.pydirectly calls C++ methods (self._obj.CreateIndexandself._obj.Optimize) without catching or enriching the errors, resulting in cryptic messages that don't help users diagnose the issue.Solution
This PR improves error handling in the Python layer to provide clearer, more actionable error messages:
Changes Made
Enhanced
create_index()method:self._obj.CreateIndex()in a try-except blockRuntimeErrorfrom C++ and re-raises with detailed contextRuntimeErrorto the Raises sectionEnhanced
optimize()method:self._obj.Optimize()in a try-except blockRuntimeErrorand provides contextual informationRuntimeErrorto the Raises section in docstringExample Error Messages
Before (cryptic):
After (informative):
Before (for optimize):
After:
Benefits
Type of Change
Testing
This change affects error paths that are already failing in issue #78. The fix:
from exc)RuntimeErrorNotes for Reviewers
Related Issues