fix: updated result to json handling to consider duplicate dataframe ids - #223
Open
frayle-ons wants to merge 1 commit into
Open
fix: updated result to json handling to consider duplicate dataframe ids#223frayle-ons wants to merge 1 commit into
frayle-ons wants to merge 1 commit into
Conversation
Contributor
|
Thanks for looking into this @frayle-ons Could I check what the reasoning behind facilitating non-unique IDs is though? |
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.
resolves #167
✨ Summary
These changes modify how the polars/dataclass dataframes are handled in:
In both these sections of the code we were grouping the dataframes by 'id' column value, to separate different queries and their results from each other. However in cases where the same 'id' value existed for multiple queries this caused some merging of independent results. For example the search results for an input search dataclass object:
would trigger undesired behaviour because during conversion of the results to a JSON object, the code
grouped = df.groupby("id")would pack all of the results from vegetable farmer and software engineer into one result.The changes made here make the package more resilient to several potential cases like this including:
idcolumn of the input to the search and reverse_search methods,query/doc_labelcolumn of the input to the search and reverse_search methodsNOTE:
However, the behaviour of ClassifAI when the user inputs 2 completely indistinguishable search inputs has odd outputs, e.g.:
still has some strange behaviours. Since this is effectively a 'duplicate' search entry, I'm not sure how this should be handled; whether to modify the existing ClassifAI code to handle this issue, or if we should introduce some new warning or a specific automatic row deduplication feature. This seems non-trivial because the user may have additional
metadatacolumns that do indicate some difference between the rows that do share the sameidandquerycolumn values. Might be a good idea to run a deduplication step where non-unique rows are removed where the entire row is non-unique, considering all columns.📜 Changes Introduced
pydantic_models.pyfile to catch cases where 'id' columns have non-unique idmain.pyfile reverse search method to catch cases whereidcolumns have non-unique values.🔍 How to Test
I have created a simple setup script to run on this current branch (it runs with our normal mock DEMO test data available from the repo. Because the servers module and the indexers module are affected, the results should be examined in both the python runtime output, and also testing on a running FastAPI server instance created with the servers module.
The final line of that code will trigger the RESTAPI server to run, and the tester may then be able to manually query the endpoints to see how the resulting data is affected by the changes. Possibly running this script on main branch and comparing would be useful too to see how the code previously caused bugs.
Some useful test cases are below for each of the affected VectorStore methods. It is worth testing these through the started RESTAPI but also just as part of Python script that accesses the VectorStore Search and Reverse Search methods. I've written these in Python code but the content can be used to understand good RESTAPI request bodies.
Append these to the end of the setup script, commenting out the
run_serverline at the end.search method test inputs:
test inputs for reverse search:
test inputs for the reverse search with partial matching enabled:
finally, and to reiterate, it is worth testing both through the server and the python runtime vectorstore methods, across this branch and main, to best see how the different dataclass inputs are handled in each unique test case.