Skip to content

Commit

Permalink
Merge pull request #31 from mariochavez/fix/update-collection-query-m…
Browse files Browse the repository at this point in the history
…ethod

Chroma's API might have changed at somepoint that made this method to pass empty Hashes an invalid request.
  • Loading branch information
mariochavez authored Dec 11, 2024
2 parents 0182576 + fc95a1a commit 727a8f8
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 103 deletions.
4 changes: 3 additions & 1 deletion lib/chroma/resources/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def initialize(id:, name:, metadata: nil)
# embeddings = collection.query(query_embeddings: [[1.5, 2.9, 3.3]], results: 5)
#
# Return an Array of Embedding with query results.
def query(query_embeddings:, results: 10, where: {}, where_document: {}, include: %w[metadatas documents distances])
def query(query_embeddings:, results: 10, where: nil, where_document: nil, include: %w[metadatas documents distances])
payload = {
query_embeddings:,
n_results: results,
Expand All @@ -43,6 +43,8 @@ def query(query_embeddings:, results: 10, where: {}, where_document: {}, include
include:
}

payload.delete_if { |_key, value| value.nil? }

result = self.class.execute_request(:post, "#{Chroma.api_url}/collections/#{id}/query", payload)

if result.success?
Expand Down
112 changes: 61 additions & 51 deletions notebook/.ipynb_checkpoints/Chroma Gem-checkpoint.ipynb

Large diffs are not rendered by default.

112 changes: 61 additions & 51 deletions notebook/Chroma Gem.ipynb

Large diffs are not rendered by default.

0 comments on commit 727a8f8

Please sign in to comment.