From fc95a1ae07990e52e5a843881a938714a3a9e907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20Alberto=20Cha=CC=81vez?= Date: Wed, 11 Dec 2024 13:41:46 -0600 Subject: [PATCH] Update Collection's query method to set nil by default for where and where_documents Chroma's API might have changed at somepoint that made this method to pass empty Hashes an invalid request. --- lib/chroma/resources/collection.rb | 4 +- .../Chroma Gem-checkpoint.ipynb | 112 ++++++++++-------- notebook/Chroma Gem.ipynb | 112 ++++++++++-------- 3 files changed, 125 insertions(+), 103 deletions(-) diff --git a/lib/chroma/resources/collection.rb b/lib/chroma/resources/collection.rb index 60c4ed3..3527c14 100644 --- a/lib/chroma/resources/collection.rb +++ b/lib/chroma/resources/collection.rb @@ -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, @@ -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? diff --git a/notebook/.ipynb_checkpoints/Chroma Gem-checkpoint.ipynb b/notebook/.ipynb_checkpoints/Chroma Gem-checkpoint.ipynb index 10b6bda..14bf7e1 100644 --- a/notebook/.ipynb_checkpoints/Chroma Gem-checkpoint.ipynb +++ b/notebook/.ipynb_checkpoints/Chroma Gem-checkpoint.ipynb @@ -53,13 +53,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "I, [2024-04-13T15:03:57.935833 #35044] INFO -- : message=Successful response code=200\n" + "I, [2024-12-11T13:38:10.661531 #16507] INFO -- : message=Successful response code=200\n" ] }, { "data": { "text/plain": [ - "\"Heartbear timestamp 1713042237898295676\"" + "\"Heartbear timestamp 1733945890642513627\"" ] }, "metadata": {}, @@ -69,13 +69,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "I, [2024-04-13T15:03:57.945292 #35044] INFO -- : message=Successful response code=200\n" + "I, [2024-12-11T13:38:10.665746 #16507] INFO -- : message=Successful response code=200\n" ] }, { "data": { "text/plain": [ - "\"Chroma server version 0.4.24\"" + "\"Chroma server version 0.5.23\"" ] }, "metadata": {}, @@ -127,7 +127,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 3, "id": "dfc806b5", "metadata": { "scrolled": true @@ -137,9 +137,9 @@ "name": "stdout", "output_type": "stream", "text": [ - "I, [2024-04-13T15:08:12.755371 #35044] INFO -- : message=Successful response code=200\n", - "I, [2024-04-13T15:08:12.775993 #35044] INFO -- : message=Successful response code=200\n", - "I, [2024-04-13T15:08:12.783116 #35044] INFO -- : message=Successful response code=200\n" + "I, [2024-12-11T13:38:20.846987 #16507] INFO -- : message=Successful response code=200\n", + "I, [2024-12-11T13:38:20.881005 #16507] INFO -- : message=Successful response code=200\n", + "I, [2024-12-11T13:38:20.884962 #16507] INFO -- : message=Successful response code=200\n" ] }, { @@ -155,13 +155,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "I, [2024-04-13T15:08:12.797436 #35044] INFO -- : message=Successful response code=200\n" + "I, [2024-12-11T13:38:20.917927 #16507] INFO -- : message=Successful response code=200\n" ] }, { "data": { "text/plain": [ - "#\"ruby\", \"gem\"=>\"chroma-rb\"}>" + "#\"ruby\", \"gem\"=>\"chroma-rb\"}>" ] }, "metadata": {}, @@ -171,7 +171,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "I, [2024-04-13T15:08:12.803337 #35044] INFO -- : message=Successful response code=200\n" + "I, [2024-12-11T13:38:20.922331 #16507] INFO -- : message=Successful response code=200\n" ] }, { @@ -187,8 +187,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "I, [2024-04-13T15:08:12.813811 #35044] INFO -- : message=Successful response code=200\n", - "I, [2024-04-13T15:08:12.818497 #35044] INFO -- : message=Successful response code=200\n" + "I, [2024-12-11T13:38:20.932971 #16507] INFO -- : message=Successful response code=200\n", + "I, [2024-12-11T13:38:20.938969 #16507] INFO -- : message=Successful response code=200\n" ] }, { @@ -204,14 +204,14 @@ "name": "stdout", "output_type": "stream", "text": [ - "I, [2024-04-13T15:08:12.830041 #35044] INFO -- : message=Successful response code=200\n", - "I, [2024-04-13T15:08:12.833464 #35044] INFO -- : message=Successful response code=200\n" + "I, [2024-12-11T13:38:20.957134 #16507] INFO -- : message=Successful response code=200\n", + "I, [2024-12-11T13:38:20.960461 #16507] INFO -- : message=Successful response code=200\n" ] }, { "data": { "text/plain": [ - "#\"chroma-rb\", \"lang\"=>\"ruby\"}>" + "#\"chroma-rb\", \"lang\"=>\"ruby\"}>" ] }, "metadata": {}, @@ -221,14 +221,14 @@ "name": "stdout", "output_type": "stream", "text": [ - "I, [2024-04-13T15:08:12.838677 #35044] INFO -- : message=Successful response code=200\n", - "I, [2024-04-13T15:08:12.843742 #35044] INFO -- : message=Successful response code=200\n" + "I, [2024-12-11T13:38:20.969917 #16507] INFO -- : message=Successful response code=200\n", + "I, [2024-12-11T13:38:20.974476 #16507] INFO -- : message=Successful response code=200\n" ] }, { "data": { "text/plain": [ - "#\"chroma-rb\", \"lang\"=>\"ruby\"}>" + "#\"chroma-rb\", \"lang\"=>\"ruby\"}>" ] }, "metadata": {}, @@ -291,7 +291,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 4, "id": "8708d9c5", "metadata": {}, "outputs": [ @@ -301,7 +301,7 @@ ":run_system" ] }, - "execution_count": 7, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -413,7 +413,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 5, "id": "f6fcee33", "metadata": {}, "outputs": [ @@ -423,7 +423,7 @@ "1" ] }, - "execution_count": 8, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -435,7 +435,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 6, "id": "f00e5431", "metadata": {}, "outputs": [ @@ -452,7 +452,7 @@ "2" ] }, - "execution_count": 9, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -465,17 +465,17 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 7, "id": "47ec27a0", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "#<#::Document:0x000000010498a8c8 @content=\"Array#any?\\n\\nany? → true or false\\nany? {|element| ... } → true or false\\nany?(obj) → true or false\\n\\nReturns true if any element of self meets a given criterion.\\n\\nWith no block given and no argument, returns true if self has any truthy element, false otherwise:\\n\\n[nil, 0, false].any? # => true\\n[nil, false].any? # => false\\n[].any? # => false\\nWith a block given and no argument, calls the block with each element in self; returns true if the block returns any truthy value, false otherwise:\\n\\n[0, 1, 2].any? {|element| element > 1 } # => true\\n[0, 1, 2].any? {|element| element > 2 } # => false\\nIf argument obj is given, returns true if obj.=== any element, false otherwise:\\n\\n['food', 'drink'].any?(/foo/) # => true\\n['food', 'drink'].any?(/bar/) # => false\\n[].any?(/foo/) # => false\\n[0, 1, 2].any?(1) # => true\\n[0, 1, 2].any?(3) # => false\\nRelated: Enumerable#any?\\n\\n\\nArray#map Array#map!\\n\\nmap {|element| ... } → new_array\\nmap → new_enumerator\\nCalls the block, if given, with each element of self; returns\", @metadata={:source=>\"ruby.txt\"}>" + "#<#::Document:0x00000001052787f0 @content=\"Array#any?\\n\\nany? → true or false\\nany? {|element| ... } → true or false\\nany?(obj) → true or false\\n\\nReturns true if any element of self meets a given criterion.\\n\\nWith no block given and no argument, returns true if self has any truthy element, false otherwise:\\n\\n[nil, 0, false].any? # => true\\n[nil, false].any? # => false\\n[].any? # => false\\nWith a block given and no argument, calls the block with each element in self; returns true if the block returns any truthy value, false otherwise:\\n\\n[0, 1, 2].any? {|element| element > 1 } # => true\\n[0, 1, 2].any? {|element| element > 2 } # => false\\nIf argument obj is given, returns true if obj.=== any element, false otherwise:\\n\\n['food', 'drink'].any?(/foo/) # => true\\n['food', 'drink'].any?(/bar/) # => false\\n[].any?(/foo/) # => false\\n[0, 1, 2].any?(1) # => true\\n[0, 1, 2].any?(3) # => false\\nRelated: Enumerable#any?\\n\\n\\nArray#map Array#map!\\n\\nmap {|element| ... } → new_array\\nmap → new_enumerator\\nCalls the block, if given, with each element of self; returns\", @metadata={:source=>\"ruby.txt\"}>" ] }, - "execution_count": 10, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -510,7 +510,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 8, "id": "02f9945a", "metadata": {}, "outputs": [ @@ -520,7 +520,7 @@ ":embed" ] }, - "execution_count": 13, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -569,14 +569,14 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 9, "id": "b8e3026f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "[#\"ruby.txt\"}, @document=\"Array#any?\\n\\nany? → true or false\\nany? {|element| ... } → true or false\\nany?(obj) → true or false\\n\\nReturns true if any element of self meets a given criterion.\\n\\nWith no block given and no argument, returns true if self has any truthy element, false otherwise:\\n\\n[nil, 0, false].any? # => true\\n[nil, false].any? # => false\\n[].any? # => false\\nWith a block given and no argument, calls the block with each element in self; returns true if the block returns any truthy value, false otherwise:\\n\\n[0, 1, 2].any? {|element| element > 1 } # => true\\n[0, 1, 2].any? {|element| element > 2 } # => false\\nIf argument obj is given, returns true if obj.=== any element, false otherwise:\\n\\n['food', 'drink'].any?(/foo/) # => true\\n['food', 'drink'].any?(/bar/) # => false\\n[].any?(/foo/) # => false\\n[0, 1, 2].any?(1) # => true\\n[0, 1, 2].any?(3) # => false\\nRelated: Enumerable#any?\\n\\n\\nArray#map Array#map!\\n\\nmap {|element| ... } → new_array\\nmap → new_enumerator\\nCalls the block, if given, with each element of self; returns\", @distance=nil>, #\"ruby.txt\"}, @document=\"true\\n[0, 1, 2].any?(3) # => false\\nRelated: Enumerable#any?\\n\\n\\nArray#map Array#map!\\n\\nmap {|element| ... } → new_array\\nmap → new_enumerator\\nCalls the block, if given, with each element of self; returns a new Array whose elements are the return values from the block:\\n\\na = [:foo, 'bar', 2]\\na1 = a.map {|element| element.class }\\na1 # => [Symbol, String, Integer]\\nReturns a new Enumerator if no block given:\\n\\na = [:foo, 'bar', 2]\\na1 = a.map\\na1 # => #\\nArray#collect is an alias for Array#map.\\n\\nAlias for: collect\\nmap! {|element| ... } → self\\nmap! → new_enumerator\\nCalls the block, if given, with each element; replaces the element with the block’s return value:\\n\\na = [:foo, 'bar', 2]\\na.map! { |element| element.class } # => [Symbol, String, Integer]\\nReturns a new Enumerator if no block given:\\n\\na = [:foo, 'bar', 2]\\na1 = a.map!\\na1 # => #\\nArray#collect! is an alias for Array#map!.\\n\\nAlias for: collect!\\n\", @distance=nil>]" + "[#\"ruby.txt\"}, @document=\"Array#any?\\n\\nany? → true or false\\nany? {|element| ... } → true or false\\nany?(obj) → true or false\\n\\nReturns true if any element of self meets a given criterion.\\n\\nWith no block given and no argument, returns true if self has any truthy element, false otherwise:\\n\\n[nil, 0, false].any? # => true\\n[nil, false].any? # => false\\n[].any? # => false\\nWith a block given and no argument, calls the block with each element in self; returns true if the block returns any truthy value, false otherwise:\\n\\n[0, 1, 2].any? {|element| element > 1 } # => true\\n[0, 1, 2].any? {|element| element > 2 } # => false\\nIf argument obj is given, returns true if obj.=== any element, false otherwise:\\n\\n['food', 'drink'].any?(/foo/) # => true\\n['food', 'drink'].any?(/bar/) # => false\\n[].any?(/foo/) # => false\\n[0, 1, 2].any?(1) # => true\\n[0, 1, 2].any?(3) # => false\\nRelated: Enumerable#any?\\n\\n\\nArray#map Array#map!\\n\\nmap {|element| ... } → new_array\\nmap → new_enumerator\\nCalls the block, if given, with each element of self; returns\", @distance=nil>, #\"ruby.txt\"}, @document=\"true\\n[0, 1, 2].any?(3) # => false\\nRelated: Enumerable#any?\\n\\n\\nArray#map Array#map!\\n\\nmap {|element| ... } → new_array\\nmap → new_enumerator\\nCalls the block, if given, with each element of self; returns a new Array whose elements are the return values from the block:\\n\\na = [:foo, 'bar', 2]\\na1 = a.map {|element| element.class }\\na1 # => [Symbol, String, Integer]\\nReturns a new Enumerator if no block given:\\n\\na = [:foo, 'bar', 2]\\na1 = a.map\\na1 # => #\\nArray#collect is an alias for Array#map.\\n\\nAlias for: collect\\nmap! {|element| ... } → self\\nmap! → new_enumerator\\nCalls the block, if given, with each element; replaces the element with the block’s return value:\\n\\na = [:foo, 'bar', 2]\\na.map! { |element| element.class } # => [Symbol, String, Integer]\\nReturns a new Enumerator if no block given:\\n\\na = [:foo, 'bar', 2]\\na1 = a.map!\\na1 # => #\\nArray#collect! is an alias for Array#map!.\\n\\nAlias for: collect!\\n\", @distance=nil>]" ] }, "metadata": {}, @@ -596,7 +596,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 10, "id": "8556fdf6", "metadata": {}, "outputs": [ @@ -604,7 +604,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "I, [2024-04-13T15:09:05.120223 #35044] INFO -- : message=Successful response code=201\n" + "I, [2024-12-11T13:38:40.349321 #16507] INFO -- : message=Successful response code=201\n" ] }, { @@ -613,7 +613,7 @@ "true" ] }, - "execution_count": 15, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -624,7 +624,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 11, "id": "b045d12d", "metadata": {}, "outputs": [ @@ -632,7 +632,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "I, [2024-04-13T15:09:08.590406 #35044] INFO -- : message=Successful response code=200\n" + "I, [2024-12-11T13:38:42.259923 #16507] INFO -- : message=Successful response code=200\n" ] }, { @@ -659,7 +659,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 12, "id": "da118706", "metadata": {}, "outputs": [ @@ -669,7 +669,7 @@ ":similarity_search" ] }, - "execution_count": 17, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -697,7 +697,7 @@ "end\n", "\n", "class ChromaVectorStore < VectorStore\n", - " def similarity_search(query, k: 4, filter: {})\n", + " def similarity_search(query, k: 4, filter: nil)\n", " query_embeddings = text_to_embeddings(query)\n", " \n", " @store.query(query_embeddings:, results: k, where: filter)\n", @@ -715,24 +715,26 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 13, "id": "e1a46ead", - "metadata": {}, + "metadata": { + "scrolled": true + }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "I, [2024-04-13T15:09:16.758519 #35044] INFO -- : message=Successful response code=200\n" + "I, [2024-12-11T13:38:46.660678 #16507] INFO -- : message=Successful response code=200\n" ] }, { "data": { "text/plain": [ - "[#\"ruby.txt\"}, @document=\"Array#any?\\n\\nany? → true or false\\nany? {|element| ... } → true or false\\nany?(obj) → true or false\\n\\nReturns true if any element of self meets a given criterion.\\n\\nWith no block given and no argument, returns true if self has any truthy element, false otherwise:\\n\\n[nil, 0, false].any? # => true\\n[nil, false].any? # => false\\n[].any? # => false\\nWith a block given and no argument, calls the block with each element in self; returns true if the block returns any truthy value, false otherwise:\\n\\n[0, 1, 2].any? {|element| element > 1 } # => true\\n[0, 1, 2].any? {|element| element > 2 } # => false\\nIf argument obj is given, returns true if obj.=== any element, false otherwise:\\n\\n['food', 'drink'].any?(/foo/) # => true\\n['food', 'drink'].any?(/bar/) # => false\\n[].any?(/foo/) # => false\\n[0, 1, 2].any?(1) # => true\\n[0, 1, 2].any?(3) # => false\\nRelated: Enumerable#any?\\n\\n\\nArray#map Array#map!\\n\\nmap {|element| ... } → new_array\\nmap → new_enumerator\\nCalls the block, if given, with each element of self; returns\", @distance=314.3061350106837>, #\"ruby.txt\"}, @document=\"true\\n[0, 1, 2].any?(3) # => false\\nRelated: Enumerable#any?\\n\\n\\nArray#map Array#map!\\n\\nmap {|element| ... } → new_array\\nmap → new_enumerator\\nCalls the block, if given, with each element of self; returns a new Array whose elements are the return values from the block:\\n\\na = [:foo, 'bar', 2]\\na1 = a.map {|element| element.class }\\na1 # => [Symbol, String, Integer]\\nReturns a new Enumerator if no block given:\\n\\na = [:foo, 'bar', 2]\\na1 = a.map\\na1 # => #\\nArray#collect is an alias for Array#map.\\n\\nAlias for: collect\\nmap! {|element| ... } → self\\nmap! → new_enumerator\\nCalls the block, if given, with each element; replaces the element with the block’s return value:\\n\\na = [:foo, 'bar', 2]\\na.map! { |element| element.class } # => [Symbol, String, Integer]\\nReturns a new Enumerator if no block given:\\n\\na = [:foo, 'bar', 2]\\na1 = a.map!\\na1 # => #\\nArray#collect! is an alias for Array#map!.\\n\\nAlias for: collect!\\n\", @distance=354.6219888629781>]" + "[#\"ruby.txt\"}, @document=\"Array#any?\\n\\nany? → true or false\\nany? {|element| ... } → true or false\\nany?(obj) → true or false\\n\\nReturns true if any element of self meets a given criterion.\\n\\nWith no block given and no argument, returns true if self has any truthy element, false otherwise:\\n\\n[nil, 0, false].any? # => true\\n[nil, false].any? # => false\\n[].any? # => false\\nWith a block given and no argument, calls the block with each element in self; returns true if the block returns any truthy value, false otherwise:\\n\\n[0, 1, 2].any? {|element| element > 1 } # => true\\n[0, 1, 2].any? {|element| element > 2 } # => false\\nIf argument obj is given, returns true if obj.=== any element, false otherwise:\\n\\n['food', 'drink'].any?(/foo/) # => true\\n['food', 'drink'].any?(/bar/) # => false\\n[].any?(/foo/) # => false\\n[0, 1, 2].any?(1) # => true\\n[0, 1, 2].any?(3) # => false\\nRelated: Enumerable#any?\\n\\n\\nArray#map Array#map!\\n\\nmap {|element| ... } → new_array\\nmap → new_enumerator\\nCalls the block, if given, with each element of self; returns\", @distance=242.9107135976995>, #\"ruby.txt\"}, @document=\"true\\n[0, 1, 2].any?(3) # => false\\nRelated: Enumerable#any?\\n\\n\\nArray#map Array#map!\\n\\nmap {|element| ... } → new_array\\nmap → new_enumerator\\nCalls the block, if given, with each element of self; returns a new Array whose elements are the return values from the block:\\n\\na = [:foo, 'bar', 2]\\na1 = a.map {|element| element.class }\\na1 # => [Symbol, String, Integer]\\nReturns a new Enumerator if no block given:\\n\\na = [:foo, 'bar', 2]\\na1 = a.map\\na1 # => #\\nArray#collect is an alias for Array#map.\\n\\nAlias for: collect\\nmap! {|element| ... } → self\\nmap! → new_enumerator\\nCalls the block, if given, with each element; replaces the element with the block’s return value:\\n\\na = [:foo, 'bar', 2]\\na.map! { |element| element.class } # => [Symbol, String, Integer]\\nReturns a new Enumerator if no block given:\\n\\na = [:foo, 'bar', 2]\\na1 = a.map!\\na1 # => #\\nArray#collect! is an alias for Array#map!.\\n\\nAlias for: collect!\\n\", @distance=281.18673467779735>]" ] }, - "execution_count": 18, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -744,17 +746,17 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 14, "id": "ab282709", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "#\"ruby.txt\"}, @document=\"Array#any?\\n\\nany? → true or false\\nany? {|element| ... } → true or false\\nany?(obj) → true or false\\n\\nReturns true if any element of self meets a given criterion.\\n\\nWith no block given and no argument, returns true if self has any truthy element, false otherwise:\\n\\n[nil, 0, false].any? # => true\\n[nil, false].any? # => false\\n[].any? # => false\\nWith a block given and no argument, calls the block with each element in self; returns true if the block returns any truthy value, false otherwise:\\n\\n[0, 1, 2].any? {|element| element > 1 } # => true\\n[0, 1, 2].any? {|element| element > 2 } # => false\\nIf argument obj is given, returns true if obj.=== any element, false otherwise:\\n\\n['food', 'drink'].any?(/foo/) # => true\\n['food', 'drink'].any?(/bar/) # => false\\n[].any?(/foo/) # => false\\n[0, 1, 2].any?(1) # => true\\n[0, 1, 2].any?(3) # => false\\nRelated: Enumerable#any?\\n\\n\\nArray#map Array#map!\\n\\nmap {|element| ... } → new_array\\nmap → new_enumerator\\nCalls the block, if given, with each element of self; returns\", @distance=314.3061350106837>" + "#\"ruby.txt\"}, @document=\"Array#any?\\n\\nany? → true or false\\nany? {|element| ... } → true or false\\nany?(obj) → true or false\\n\\nReturns true if any element of self meets a given criterion.\\n\\nWith no block given and no argument, returns true if self has any truthy element, false otherwise:\\n\\n[nil, 0, false].any? # => true\\n[nil, false].any? # => false\\n[].any? # => false\\nWith a block given and no argument, calls the block with each element in self; returns true if the block returns any truthy value, false otherwise:\\n\\n[0, 1, 2].any? {|element| element > 1 } # => true\\n[0, 1, 2].any? {|element| element > 2 } # => false\\nIf argument obj is given, returns true if obj.=== any element, false otherwise:\\n\\n['food', 'drink'].any?(/foo/) # => true\\n['food', 'drink'].any?(/bar/) # => false\\n[].any?(/foo/) # => false\\n[0, 1, 2].any?(1) # => true\\n[0, 1, 2].any?(3) # => false\\nRelated: Enumerable#any?\\n\\n\\nArray#map Array#map!\\n\\nmap {|element| ... } → new_array\\nmap → new_enumerator\\nCalls the block, if given, with each element of self; returns\", @distance=242.9107135976995>" ] }, - "execution_count": 19, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -762,19 +764,27 @@ "source": [ "embeddings[0]" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "60c017bf", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Ruby 3.2.2", + "display_name": "Ruby 3 (iruby kernel)", "language": "ruby", - "name": "ruby" + "name": "ruby3" }, "language_info": { "file_extension": ".rb", "mimetype": "application/x-ruby", "name": "ruby", - "version": "3.2.2" + "version": "3.3.5" } }, "nbformat": 4, diff --git a/notebook/Chroma Gem.ipynb b/notebook/Chroma Gem.ipynb index 10b6bda..14bf7e1 100644 --- a/notebook/Chroma Gem.ipynb +++ b/notebook/Chroma Gem.ipynb @@ -53,13 +53,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "I, [2024-04-13T15:03:57.935833 #35044] INFO -- : message=Successful response code=200\n" + "I, [2024-12-11T13:38:10.661531 #16507] INFO -- : message=Successful response code=200\n" ] }, { "data": { "text/plain": [ - "\"Heartbear timestamp 1713042237898295676\"" + "\"Heartbear timestamp 1733945890642513627\"" ] }, "metadata": {}, @@ -69,13 +69,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "I, [2024-04-13T15:03:57.945292 #35044] INFO -- : message=Successful response code=200\n" + "I, [2024-12-11T13:38:10.665746 #16507] INFO -- : message=Successful response code=200\n" ] }, { "data": { "text/plain": [ - "\"Chroma server version 0.4.24\"" + "\"Chroma server version 0.5.23\"" ] }, "metadata": {}, @@ -127,7 +127,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 3, "id": "dfc806b5", "metadata": { "scrolled": true @@ -137,9 +137,9 @@ "name": "stdout", "output_type": "stream", "text": [ - "I, [2024-04-13T15:08:12.755371 #35044] INFO -- : message=Successful response code=200\n", - "I, [2024-04-13T15:08:12.775993 #35044] INFO -- : message=Successful response code=200\n", - "I, [2024-04-13T15:08:12.783116 #35044] INFO -- : message=Successful response code=200\n" + "I, [2024-12-11T13:38:20.846987 #16507] INFO -- : message=Successful response code=200\n", + "I, [2024-12-11T13:38:20.881005 #16507] INFO -- : message=Successful response code=200\n", + "I, [2024-12-11T13:38:20.884962 #16507] INFO -- : message=Successful response code=200\n" ] }, { @@ -155,13 +155,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "I, [2024-04-13T15:08:12.797436 #35044] INFO -- : message=Successful response code=200\n" + "I, [2024-12-11T13:38:20.917927 #16507] INFO -- : message=Successful response code=200\n" ] }, { "data": { "text/plain": [ - "#\"ruby\", \"gem\"=>\"chroma-rb\"}>" + "#\"ruby\", \"gem\"=>\"chroma-rb\"}>" ] }, "metadata": {}, @@ -171,7 +171,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "I, [2024-04-13T15:08:12.803337 #35044] INFO -- : message=Successful response code=200\n" + "I, [2024-12-11T13:38:20.922331 #16507] INFO -- : message=Successful response code=200\n" ] }, { @@ -187,8 +187,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "I, [2024-04-13T15:08:12.813811 #35044] INFO -- : message=Successful response code=200\n", - "I, [2024-04-13T15:08:12.818497 #35044] INFO -- : message=Successful response code=200\n" + "I, [2024-12-11T13:38:20.932971 #16507] INFO -- : message=Successful response code=200\n", + "I, [2024-12-11T13:38:20.938969 #16507] INFO -- : message=Successful response code=200\n" ] }, { @@ -204,14 +204,14 @@ "name": "stdout", "output_type": "stream", "text": [ - "I, [2024-04-13T15:08:12.830041 #35044] INFO -- : message=Successful response code=200\n", - "I, [2024-04-13T15:08:12.833464 #35044] INFO -- : message=Successful response code=200\n" + "I, [2024-12-11T13:38:20.957134 #16507] INFO -- : message=Successful response code=200\n", + "I, [2024-12-11T13:38:20.960461 #16507] INFO -- : message=Successful response code=200\n" ] }, { "data": { "text/plain": [ - "#\"chroma-rb\", \"lang\"=>\"ruby\"}>" + "#\"chroma-rb\", \"lang\"=>\"ruby\"}>" ] }, "metadata": {}, @@ -221,14 +221,14 @@ "name": "stdout", "output_type": "stream", "text": [ - "I, [2024-04-13T15:08:12.838677 #35044] INFO -- : message=Successful response code=200\n", - "I, [2024-04-13T15:08:12.843742 #35044] INFO -- : message=Successful response code=200\n" + "I, [2024-12-11T13:38:20.969917 #16507] INFO -- : message=Successful response code=200\n", + "I, [2024-12-11T13:38:20.974476 #16507] INFO -- : message=Successful response code=200\n" ] }, { "data": { "text/plain": [ - "#\"chroma-rb\", \"lang\"=>\"ruby\"}>" + "#\"chroma-rb\", \"lang\"=>\"ruby\"}>" ] }, "metadata": {}, @@ -291,7 +291,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 4, "id": "8708d9c5", "metadata": {}, "outputs": [ @@ -301,7 +301,7 @@ ":run_system" ] }, - "execution_count": 7, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -413,7 +413,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 5, "id": "f6fcee33", "metadata": {}, "outputs": [ @@ -423,7 +423,7 @@ "1" ] }, - "execution_count": 8, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -435,7 +435,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 6, "id": "f00e5431", "metadata": {}, "outputs": [ @@ -452,7 +452,7 @@ "2" ] }, - "execution_count": 9, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -465,17 +465,17 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 7, "id": "47ec27a0", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "#<#::Document:0x000000010498a8c8 @content=\"Array#any?\\n\\nany? → true or false\\nany? {|element| ... } → true or false\\nany?(obj) → true or false\\n\\nReturns true if any element of self meets a given criterion.\\n\\nWith no block given and no argument, returns true if self has any truthy element, false otherwise:\\n\\n[nil, 0, false].any? # => true\\n[nil, false].any? # => false\\n[].any? # => false\\nWith a block given and no argument, calls the block with each element in self; returns true if the block returns any truthy value, false otherwise:\\n\\n[0, 1, 2].any? {|element| element > 1 } # => true\\n[0, 1, 2].any? {|element| element > 2 } # => false\\nIf argument obj is given, returns true if obj.=== any element, false otherwise:\\n\\n['food', 'drink'].any?(/foo/) # => true\\n['food', 'drink'].any?(/bar/) # => false\\n[].any?(/foo/) # => false\\n[0, 1, 2].any?(1) # => true\\n[0, 1, 2].any?(3) # => false\\nRelated: Enumerable#any?\\n\\n\\nArray#map Array#map!\\n\\nmap {|element| ... } → new_array\\nmap → new_enumerator\\nCalls the block, if given, with each element of self; returns\", @metadata={:source=>\"ruby.txt\"}>" + "#<#::Document:0x00000001052787f0 @content=\"Array#any?\\n\\nany? → true or false\\nany? {|element| ... } → true or false\\nany?(obj) → true or false\\n\\nReturns true if any element of self meets a given criterion.\\n\\nWith no block given and no argument, returns true if self has any truthy element, false otherwise:\\n\\n[nil, 0, false].any? # => true\\n[nil, false].any? # => false\\n[].any? # => false\\nWith a block given and no argument, calls the block with each element in self; returns true if the block returns any truthy value, false otherwise:\\n\\n[0, 1, 2].any? {|element| element > 1 } # => true\\n[0, 1, 2].any? {|element| element > 2 } # => false\\nIf argument obj is given, returns true if obj.=== any element, false otherwise:\\n\\n['food', 'drink'].any?(/foo/) # => true\\n['food', 'drink'].any?(/bar/) # => false\\n[].any?(/foo/) # => false\\n[0, 1, 2].any?(1) # => true\\n[0, 1, 2].any?(3) # => false\\nRelated: Enumerable#any?\\n\\n\\nArray#map Array#map!\\n\\nmap {|element| ... } → new_array\\nmap → new_enumerator\\nCalls the block, if given, with each element of self; returns\", @metadata={:source=>\"ruby.txt\"}>" ] }, - "execution_count": 10, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -510,7 +510,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 8, "id": "02f9945a", "metadata": {}, "outputs": [ @@ -520,7 +520,7 @@ ":embed" ] }, - "execution_count": 13, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -569,14 +569,14 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 9, "id": "b8e3026f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "[#\"ruby.txt\"}, @document=\"Array#any?\\n\\nany? → true or false\\nany? {|element| ... } → true or false\\nany?(obj) → true or false\\n\\nReturns true if any element of self meets a given criterion.\\n\\nWith no block given and no argument, returns true if self has any truthy element, false otherwise:\\n\\n[nil, 0, false].any? # => true\\n[nil, false].any? # => false\\n[].any? # => false\\nWith a block given and no argument, calls the block with each element in self; returns true if the block returns any truthy value, false otherwise:\\n\\n[0, 1, 2].any? {|element| element > 1 } # => true\\n[0, 1, 2].any? {|element| element > 2 } # => false\\nIf argument obj is given, returns true if obj.=== any element, false otherwise:\\n\\n['food', 'drink'].any?(/foo/) # => true\\n['food', 'drink'].any?(/bar/) # => false\\n[].any?(/foo/) # => false\\n[0, 1, 2].any?(1) # => true\\n[0, 1, 2].any?(3) # => false\\nRelated: Enumerable#any?\\n\\n\\nArray#map Array#map!\\n\\nmap {|element| ... } → new_array\\nmap → new_enumerator\\nCalls the block, if given, with each element of self; returns\", @distance=nil>, #\"ruby.txt\"}, @document=\"true\\n[0, 1, 2].any?(3) # => false\\nRelated: Enumerable#any?\\n\\n\\nArray#map Array#map!\\n\\nmap {|element| ... } → new_array\\nmap → new_enumerator\\nCalls the block, if given, with each element of self; returns a new Array whose elements are the return values from the block:\\n\\na = [:foo, 'bar', 2]\\na1 = a.map {|element| element.class }\\na1 # => [Symbol, String, Integer]\\nReturns a new Enumerator if no block given:\\n\\na = [:foo, 'bar', 2]\\na1 = a.map\\na1 # => #\\nArray#collect is an alias for Array#map.\\n\\nAlias for: collect\\nmap! {|element| ... } → self\\nmap! → new_enumerator\\nCalls the block, if given, with each element; replaces the element with the block’s return value:\\n\\na = [:foo, 'bar', 2]\\na.map! { |element| element.class } # => [Symbol, String, Integer]\\nReturns a new Enumerator if no block given:\\n\\na = [:foo, 'bar', 2]\\na1 = a.map!\\na1 # => #\\nArray#collect! is an alias for Array#map!.\\n\\nAlias for: collect!\\n\", @distance=nil>]" + "[#\"ruby.txt\"}, @document=\"Array#any?\\n\\nany? → true or false\\nany? {|element| ... } → true or false\\nany?(obj) → true or false\\n\\nReturns true if any element of self meets a given criterion.\\n\\nWith no block given and no argument, returns true if self has any truthy element, false otherwise:\\n\\n[nil, 0, false].any? # => true\\n[nil, false].any? # => false\\n[].any? # => false\\nWith a block given and no argument, calls the block with each element in self; returns true if the block returns any truthy value, false otherwise:\\n\\n[0, 1, 2].any? {|element| element > 1 } # => true\\n[0, 1, 2].any? {|element| element > 2 } # => false\\nIf argument obj is given, returns true if obj.=== any element, false otherwise:\\n\\n['food', 'drink'].any?(/foo/) # => true\\n['food', 'drink'].any?(/bar/) # => false\\n[].any?(/foo/) # => false\\n[0, 1, 2].any?(1) # => true\\n[0, 1, 2].any?(3) # => false\\nRelated: Enumerable#any?\\n\\n\\nArray#map Array#map!\\n\\nmap {|element| ... } → new_array\\nmap → new_enumerator\\nCalls the block, if given, with each element of self; returns\", @distance=nil>, #\"ruby.txt\"}, @document=\"true\\n[0, 1, 2].any?(3) # => false\\nRelated: Enumerable#any?\\n\\n\\nArray#map Array#map!\\n\\nmap {|element| ... } → new_array\\nmap → new_enumerator\\nCalls the block, if given, with each element of self; returns a new Array whose elements are the return values from the block:\\n\\na = [:foo, 'bar', 2]\\na1 = a.map {|element| element.class }\\na1 # => [Symbol, String, Integer]\\nReturns a new Enumerator if no block given:\\n\\na = [:foo, 'bar', 2]\\na1 = a.map\\na1 # => #\\nArray#collect is an alias for Array#map.\\n\\nAlias for: collect\\nmap! {|element| ... } → self\\nmap! → new_enumerator\\nCalls the block, if given, with each element; replaces the element with the block’s return value:\\n\\na = [:foo, 'bar', 2]\\na.map! { |element| element.class } # => [Symbol, String, Integer]\\nReturns a new Enumerator if no block given:\\n\\na = [:foo, 'bar', 2]\\na1 = a.map!\\na1 # => #\\nArray#collect! is an alias for Array#map!.\\n\\nAlias for: collect!\\n\", @distance=nil>]" ] }, "metadata": {}, @@ -596,7 +596,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 10, "id": "8556fdf6", "metadata": {}, "outputs": [ @@ -604,7 +604,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "I, [2024-04-13T15:09:05.120223 #35044] INFO -- : message=Successful response code=201\n" + "I, [2024-12-11T13:38:40.349321 #16507] INFO -- : message=Successful response code=201\n" ] }, { @@ -613,7 +613,7 @@ "true" ] }, - "execution_count": 15, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -624,7 +624,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 11, "id": "b045d12d", "metadata": {}, "outputs": [ @@ -632,7 +632,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "I, [2024-04-13T15:09:08.590406 #35044] INFO -- : message=Successful response code=200\n" + "I, [2024-12-11T13:38:42.259923 #16507] INFO -- : message=Successful response code=200\n" ] }, { @@ -659,7 +659,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 12, "id": "da118706", "metadata": {}, "outputs": [ @@ -669,7 +669,7 @@ ":similarity_search" ] }, - "execution_count": 17, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -697,7 +697,7 @@ "end\n", "\n", "class ChromaVectorStore < VectorStore\n", - " def similarity_search(query, k: 4, filter: {})\n", + " def similarity_search(query, k: 4, filter: nil)\n", " query_embeddings = text_to_embeddings(query)\n", " \n", " @store.query(query_embeddings:, results: k, where: filter)\n", @@ -715,24 +715,26 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 13, "id": "e1a46ead", - "metadata": {}, + "metadata": { + "scrolled": true + }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "I, [2024-04-13T15:09:16.758519 #35044] INFO -- : message=Successful response code=200\n" + "I, [2024-12-11T13:38:46.660678 #16507] INFO -- : message=Successful response code=200\n" ] }, { "data": { "text/plain": [ - "[#\"ruby.txt\"}, @document=\"Array#any?\\n\\nany? → true or false\\nany? {|element| ... } → true or false\\nany?(obj) → true or false\\n\\nReturns true if any element of self meets a given criterion.\\n\\nWith no block given and no argument, returns true if self has any truthy element, false otherwise:\\n\\n[nil, 0, false].any? # => true\\n[nil, false].any? # => false\\n[].any? # => false\\nWith a block given and no argument, calls the block with each element in self; returns true if the block returns any truthy value, false otherwise:\\n\\n[0, 1, 2].any? {|element| element > 1 } # => true\\n[0, 1, 2].any? {|element| element > 2 } # => false\\nIf argument obj is given, returns true if obj.=== any element, false otherwise:\\n\\n['food', 'drink'].any?(/foo/) # => true\\n['food', 'drink'].any?(/bar/) # => false\\n[].any?(/foo/) # => false\\n[0, 1, 2].any?(1) # => true\\n[0, 1, 2].any?(3) # => false\\nRelated: Enumerable#any?\\n\\n\\nArray#map Array#map!\\n\\nmap {|element| ... } → new_array\\nmap → new_enumerator\\nCalls the block, if given, with each element of self; returns\", @distance=314.3061350106837>, #\"ruby.txt\"}, @document=\"true\\n[0, 1, 2].any?(3) # => false\\nRelated: Enumerable#any?\\n\\n\\nArray#map Array#map!\\n\\nmap {|element| ... } → new_array\\nmap → new_enumerator\\nCalls the block, if given, with each element of self; returns a new Array whose elements are the return values from the block:\\n\\na = [:foo, 'bar', 2]\\na1 = a.map {|element| element.class }\\na1 # => [Symbol, String, Integer]\\nReturns a new Enumerator if no block given:\\n\\na = [:foo, 'bar', 2]\\na1 = a.map\\na1 # => #\\nArray#collect is an alias for Array#map.\\n\\nAlias for: collect\\nmap! {|element| ... } → self\\nmap! → new_enumerator\\nCalls the block, if given, with each element; replaces the element with the block’s return value:\\n\\na = [:foo, 'bar', 2]\\na.map! { |element| element.class } # => [Symbol, String, Integer]\\nReturns a new Enumerator if no block given:\\n\\na = [:foo, 'bar', 2]\\na1 = a.map!\\na1 # => #\\nArray#collect! is an alias for Array#map!.\\n\\nAlias for: collect!\\n\", @distance=354.6219888629781>]" + "[#\"ruby.txt\"}, @document=\"Array#any?\\n\\nany? → true or false\\nany? {|element| ... } → true or false\\nany?(obj) → true or false\\n\\nReturns true if any element of self meets a given criterion.\\n\\nWith no block given and no argument, returns true if self has any truthy element, false otherwise:\\n\\n[nil, 0, false].any? # => true\\n[nil, false].any? # => false\\n[].any? # => false\\nWith a block given and no argument, calls the block with each element in self; returns true if the block returns any truthy value, false otherwise:\\n\\n[0, 1, 2].any? {|element| element > 1 } # => true\\n[0, 1, 2].any? {|element| element > 2 } # => false\\nIf argument obj is given, returns true if obj.=== any element, false otherwise:\\n\\n['food', 'drink'].any?(/foo/) # => true\\n['food', 'drink'].any?(/bar/) # => false\\n[].any?(/foo/) # => false\\n[0, 1, 2].any?(1) # => true\\n[0, 1, 2].any?(3) # => false\\nRelated: Enumerable#any?\\n\\n\\nArray#map Array#map!\\n\\nmap {|element| ... } → new_array\\nmap → new_enumerator\\nCalls the block, if given, with each element of self; returns\", @distance=242.9107135976995>, #\"ruby.txt\"}, @document=\"true\\n[0, 1, 2].any?(3) # => false\\nRelated: Enumerable#any?\\n\\n\\nArray#map Array#map!\\n\\nmap {|element| ... } → new_array\\nmap → new_enumerator\\nCalls the block, if given, with each element of self; returns a new Array whose elements are the return values from the block:\\n\\na = [:foo, 'bar', 2]\\na1 = a.map {|element| element.class }\\na1 # => [Symbol, String, Integer]\\nReturns a new Enumerator if no block given:\\n\\na = [:foo, 'bar', 2]\\na1 = a.map\\na1 # => #\\nArray#collect is an alias for Array#map.\\n\\nAlias for: collect\\nmap! {|element| ... } → self\\nmap! → new_enumerator\\nCalls the block, if given, with each element; replaces the element with the block’s return value:\\n\\na = [:foo, 'bar', 2]\\na.map! { |element| element.class } # => [Symbol, String, Integer]\\nReturns a new Enumerator if no block given:\\n\\na = [:foo, 'bar', 2]\\na1 = a.map!\\na1 # => #\\nArray#collect! is an alias for Array#map!.\\n\\nAlias for: collect!\\n\", @distance=281.18673467779735>]" ] }, - "execution_count": 18, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -744,17 +746,17 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 14, "id": "ab282709", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "#\"ruby.txt\"}, @document=\"Array#any?\\n\\nany? → true or false\\nany? {|element| ... } → true or false\\nany?(obj) → true or false\\n\\nReturns true if any element of self meets a given criterion.\\n\\nWith no block given and no argument, returns true if self has any truthy element, false otherwise:\\n\\n[nil, 0, false].any? # => true\\n[nil, false].any? # => false\\n[].any? # => false\\nWith a block given and no argument, calls the block with each element in self; returns true if the block returns any truthy value, false otherwise:\\n\\n[0, 1, 2].any? {|element| element > 1 } # => true\\n[0, 1, 2].any? {|element| element > 2 } # => false\\nIf argument obj is given, returns true if obj.=== any element, false otherwise:\\n\\n['food', 'drink'].any?(/foo/) # => true\\n['food', 'drink'].any?(/bar/) # => false\\n[].any?(/foo/) # => false\\n[0, 1, 2].any?(1) # => true\\n[0, 1, 2].any?(3) # => false\\nRelated: Enumerable#any?\\n\\n\\nArray#map Array#map!\\n\\nmap {|element| ... } → new_array\\nmap → new_enumerator\\nCalls the block, if given, with each element of self; returns\", @distance=314.3061350106837>" + "#\"ruby.txt\"}, @document=\"Array#any?\\n\\nany? → true or false\\nany? {|element| ... } → true or false\\nany?(obj) → true or false\\n\\nReturns true if any element of self meets a given criterion.\\n\\nWith no block given and no argument, returns true if self has any truthy element, false otherwise:\\n\\n[nil, 0, false].any? # => true\\n[nil, false].any? # => false\\n[].any? # => false\\nWith a block given and no argument, calls the block with each element in self; returns true if the block returns any truthy value, false otherwise:\\n\\n[0, 1, 2].any? {|element| element > 1 } # => true\\n[0, 1, 2].any? {|element| element > 2 } # => false\\nIf argument obj is given, returns true if obj.=== any element, false otherwise:\\n\\n['food', 'drink'].any?(/foo/) # => true\\n['food', 'drink'].any?(/bar/) # => false\\n[].any?(/foo/) # => false\\n[0, 1, 2].any?(1) # => true\\n[0, 1, 2].any?(3) # => false\\nRelated: Enumerable#any?\\n\\n\\nArray#map Array#map!\\n\\nmap {|element| ... } → new_array\\nmap → new_enumerator\\nCalls the block, if given, with each element of self; returns\", @distance=242.9107135976995>" ] }, - "execution_count": 19, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -762,19 +764,27 @@ "source": [ "embeddings[0]" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "60c017bf", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Ruby 3.2.2", + "display_name": "Ruby 3 (iruby kernel)", "language": "ruby", - "name": "ruby" + "name": "ruby3" }, "language_info": { "file_extension": ".rb", "mimetype": "application/x-ruby", "name": "ruby", - "version": "3.2.2" + "version": "3.3.5" } }, "nbformat": 4,