fix(python): resolve multi-index search core dumps by exposing missing state (#643)#754
Open
Abhinav2656 wants to merge 1 commit into
Open
fix(python): resolve multi-index search core dumps by exposing missing state (#643)#754Abhinav2656 wants to merge 1 commit into
Abhinav2656 wants to merge 1 commit into
Conversation
…earch core dumps Resolves unum-cloud#643 by exposing ndim, dtype, and metric properties in the multi-index wrapper and retaining references to underlying Index objects to prevent premature garbage collection of metric functions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #643:
Mult-Index Search Doesn't Work in PythonRoot Cause Analysis
When utilizing the Python bindings for multi-index search,
ix.search(query)was failing violently via either a PythonValueError(dimension mismatch) or a C++std::bad_function_call(core dump).This occurred because the
Indexeswrapper class dropped the state of its underlyingIndexchildren upon initialization:Indexesclass lacked thendim,dtype, andmetricproperties required by_search_in_compiled.Indexes.__init__method consumed an iterable ofIndexobjects, passed their compiled pointers to C++, and then immediately discarded the Python objects. If instantiated with anonymous objects, Python's garbage collector destroyed the underlying indices, leaving the C++ core with null pointers to metric functions (triggering thestd::bad_function_call).The Fix
self.indiceswithin theIndexesconstructor to ensure the Python objects (and their C++ metric callbacks) survive garbage collection.@propertymethods forndim,dtype, andmetricon theIndexesclass that dynamically inherit the architectural state from the first underlying index in the collection.Validation
Added
test_multi_indexto the Python test suite to strictly verify:Indexes([])gracefully returns0/None/unknown.np.vstack) across the boundary without dimension mismatch errors.