Skip to content

[ENH] Add support to convert Get/QueryResult to pandas dataframe #4304

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

Merged
merged 1 commit into from
May 5, 2025

Conversation

jairad26
Copy link
Contributor

@jairad26 jairad26 commented Apr 16, 2025

Description of changes

This PR adds support to convert both get and query results to pandas dataframes. As a byproduct, users can now get results in row format.

Test plan

How are these changes tested?

  • Tests pass locally with pytest for python, yarn test for js, cargo test for rust

Documentation Changes

Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the docs repository?

Copy link

Reviewer Checklist

Please leverage this checklist to ensure your code review is thorough before approving

Testing, Bugs, Errors, Logs, Documentation

  • Can you think of any use case in which the code does not behave as intended? Have they been tested?
  • Can you think of any inputs or external events that could break the code? Is user input validated and safe? Have they been tested?
  • If appropriate, are there adequate property based tests?
  • If appropriate, are there adequate unit tests?
  • Should any logging, debugging, tracing information be added or removed?
  • Are error messages user-friendly?
  • Have all documentation changes needed been made?
  • Have all non-obvious changes been commented?

System Compatibility

  • Are there any potential impacts on other parts of the system or backward compatibility?
  • Does this change intersect with any items on our roadmap, and if so, is there a plan for fitting them together?

Quality

  • Is this code of a unexpectedly high quality (Readability, Modularity, Intuitiveness)

Copy link
Contributor Author

jairad26 commented Apr 16, 2025

@jairad26 jairad26 marked this pull request as ready for review April 16, 2025 23:20
@@ -419,6 +419,10 @@ class QueryResult(TypedDict):
included: Include


# Type alias for union of result types
GetOrQueryResult = Union["QueryResult", "GetResult"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should do two different types here. Commingling them makes it more complicated than necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

separated, now theres 2 functions: query_result_to_df and get_result_to_df


data_for_df["id"] = query_result["ids"][i]

if "documents" in included_fields and query_result["documents"] is not None:
Copy link
Collaborator

@HammadB HammadB Apr 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we generalize this behavior into a helper? Its all the same

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@jairad26 jairad26 force-pushed the jai/df-query-res branch 2 times, most recently from 4647db9 to 3b3363d Compare April 29, 2025 21:54
Copy link
Collaborator

@HammadB HammadB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Please add tests
  • Pandas is not a explicit dep of chroma. Maybe we should error if its not installed.

@jairad26 jairad26 force-pushed the jai/df-query-res branch 6 times, most recently from 97ed1a2 to b705d6d Compare April 30, 2025 19:15
@jairad26 jairad26 merged commit 79a3dec into main May 5, 2025
70 checks passed
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.

2 participants