From 0d79e836d44bcffe486b11518a544c50d24717d8 Mon Sep 17 00:00:00 2001 From: Andrei Bondarev Date: Mon, 1 Jul 2024 14:25:02 -0400 Subject: [PATCH 1/2] Add Milvus#remove_texts() method --- lib/langchain/vectorsearch/milvus.rb | 17 ++++++++++++++++- spec/langchain/vectorsearch/milvus_spec.rb | 12 ++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/langchain/vectorsearch/milvus.rb b/lib/langchain/vectorsearch/milvus.rb index 4a6e77562..b2eb00116 100644 --- a/lib/langchain/vectorsearch/milvus.rb +++ b/lib/langchain/vectorsearch/milvus.rb @@ -39,6 +39,21 @@ def add_texts(texts:) ) end + # Deletes a list of texts in the index + # + # @param ids [Array] The ids of texts to delete + # @return [Boolean] The response from the server + def remove_texts(ids:) + raise ArgumentError, "ids must be an array" unless ids.is_a?(Array) + # Convert ids to integers if strings are passed + ids = ids.map(&:to_i) + + client.entities.delete( + collection_name: index_name, + expression: "id in #{ids}" + ) + end + # TODO: Add update_texts method # Create default schema @@ -83,7 +98,7 @@ def create_default_schema # @return [Boolean] The response from the server def create_default_index client.indices.create( - collection_name: "Documents", + collection_name: index_name, field_name: "vectors", extra_params: [ {key: "metric_type", value: "L2"}, diff --git a/spec/langchain/vectorsearch/milvus_spec.rb b/spec/langchain/vectorsearch/milvus_spec.rb index c4741c920..6a316ee69 100644 --- a/spec/langchain/vectorsearch/milvus_spec.rb +++ b/spec/langchain/vectorsearch/milvus_spec.rb @@ -89,6 +89,18 @@ end end + describe "remove_texts" do + let(:response) { {"status" => {}, "IDs" => {"IdField" => nil}, "delete_cnt" => 1} } + + before do + allow(subject.client).to receive_message_chain(:entities, :delete).and_return(response) + end + + it "adds texts" do + expect(subject.remove_texts(ids: [450847466900986695])).to eq(response) + end + end + describe "#similarity_search_by_vector" do before do allow(subject.client.collections).to receive(:load).and_return(true) From f0a808344a2997bc9a2cdf3f8714343acb6ca1f1 Mon Sep 17 00:00:00 2001 From: Andrei Bondarev Date: Mon, 1 Jul 2024 14:29:34 -0400 Subject: [PATCH 2/2] Bump milvus gem --- Gemfile.lock | 4 ++-- README.md | 2 +- langchain.gemspec | 2 +- lib/langchain/vectorsearch/milvus.rb | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 510f93b86..170e49419 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -214,7 +214,7 @@ GEM net-smtp matrix (0.4.2) method_source (1.1.0) - milvus (0.9.2) + milvus (0.9.3) faraday (>= 2.0.1, < 3) mini_mime (1.1.5) mini_portile2 (2.8.6) @@ -479,7 +479,7 @@ DEPENDENCIES langchainrb! llama_cpp (~> 0.9.4) mail (~> 2.8) - milvus (~> 0.9.2) + milvus (~> 0.9.3) mistral-ai nokogiri (~> 1.13) open-weather-ruby-client (~> 0.4.0) diff --git a/README.md b/README.md index a1f5fc464..6387984d7 100644 --- a/README.md +++ b/README.md @@ -343,7 +343,7 @@ You can instantiate any other supported vector search database: client = Langchain::Vectorsearch::Chroma.new(...) # `gem "chroma-db", "~> 0.6.0"` client = Langchain::Vectorsearch::Epsilla.new(...) # `gem "epsilla-ruby", "~> 0.0.3"` client = Langchain::Vectorsearch::Hnswlib.new(...) # `gem "hnswlib", "~> 0.8.1"` -client = Langchain::Vectorsearch::Milvus.new(...) # `gem "milvus", "~> 0.9.2"` +client = Langchain::Vectorsearch::Milvus.new(...) # `gem "milvus", "~> 0.9.3"` client = Langchain::Vectorsearch::Pinecone.new(...) # `gem "pinecone", "~> 0.1.6"` client = Langchain::Vectorsearch::Pgvector.new(...) # `gem "pgvector", "~> 0.2"` client = Langchain::Vectorsearch::Qdrant.new(...) # `gem "qdrant-ruby", "~> 0.9.3"` diff --git a/langchain.gemspec b/langchain.gemspec index 2f8e71c62..13e0e7bd2 100644 --- a/langchain.gemspec +++ b/langchain.gemspec @@ -59,7 +59,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency "google_search_results", "~> 2.0.0" spec.add_development_dependency "hnswlib", "~> 0.8.1" spec.add_development_dependency "hugging-face", "~> 0.3.4" - spec.add_development_dependency "milvus", "~> 0.9.2" + spec.add_development_dependency "milvus", "~> 0.9.3" spec.add_development_dependency "llama_cpp", "~> 0.9.4" spec.add_development_dependency "nokogiri", "~> 1.13" spec.add_development_dependency "mail", "~> 2.8" diff --git a/lib/langchain/vectorsearch/milvus.rb b/lib/langchain/vectorsearch/milvus.rb index b2eb00116..9c6532118 100644 --- a/lib/langchain/vectorsearch/milvus.rb +++ b/lib/langchain/vectorsearch/milvus.rb @@ -6,7 +6,7 @@ class Milvus < Base # Wrapper around Milvus REST APIs. # # Gem requirements: - # gem "milvus", "~> 0.9.2" + # gem "milvus", "~> 0.9.3" # # Usage: # milvus = Langchain::Vectorsearch::Milvus.new(url:, index_name:, llm:, api_key:)