From 418ffb31b1039b25e9fcdcc4a21b29d0da0e77d5 Mon Sep 17 00:00:00 2001 From: capak07 <69026837+capak07@users.noreply.github.com> Date: Sun, 7 Apr 2024 22:10:49 -0300 Subject: [PATCH 1/3] Added remove_texts method in WeaviateSearch --- lib/langchain/vectorsearch/weaviate.rb | 9 +++++++++ spec/langchain/vectorsearch/weaviate_spec.rb | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/langchain/vectorsearch/weaviate.rb b/lib/langchain/vectorsearch/weaviate.rb index 46d25458d..e2e60db85 100644 --- a/lib/langchain/vectorsearch/weaviate.rb +++ b/lib/langchain/vectorsearch/weaviate.rb @@ -71,6 +71,15 @@ def update_texts(texts:, ids:) end end + def remove_texts(ids:) + ids.map do |id| + client.objects.delete( + class_name: index_name, + id: id + ) + end + end + # Create default schema # @return [Hash] The response from the server def create_default_schema diff --git a/spec/langchain/vectorsearch/weaviate_spec.rb b/spec/langchain/vectorsearch/weaviate_spec.rb index c40f92f59..bb1785f31 100644 --- a/spec/langchain/vectorsearch/weaviate_spec.rb +++ b/spec/langchain/vectorsearch/weaviate_spec.rb @@ -120,6 +120,22 @@ def stub(id) end end + describe "#remove_texts" do + + let(:record) { + [{"_additional" => {"id" => "372ba500-01af-4448-aa03-21f3dd25a456"}}] + } + + before do + allow(subject.client.query).to receive(:get).and_return(record) + allow(subject.client.objects).to receive(:delete).and_return(true) + end + + it "removes texts" do + expect(subject.remove_texts(ids: [1])).to eq([true]) + end + end + describe "#similarity_search" do let(:fixture) { JSON.parse(File.read("spec/fixtures/vectorsearch/weaviate/search.json")) } From ba95ce3e7b69848d4412763b0d0ea2ac84947991 Mon Sep 17 00:00:00 2001 From: capak07 <69026837+capak07@users.noreply.github.com> Date: Sun, 7 Apr 2024 23:28:39 -0300 Subject: [PATCH 2/3] Resolved linter issue --- spec/langchain/vectorsearch/weaviate_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/langchain/vectorsearch/weaviate_spec.rb b/spec/langchain/vectorsearch/weaviate_spec.rb index bb1785f31..a8af137b3 100644 --- a/spec/langchain/vectorsearch/weaviate_spec.rb +++ b/spec/langchain/vectorsearch/weaviate_spec.rb @@ -121,7 +121,6 @@ def stub(id) end describe "#remove_texts" do - let(:record) { [{"_additional" => {"id" => "372ba500-01af-4448-aa03-21f3dd25a456"}}] } From dfcdf690c2c4c75c29a5025e9fcb680697f30f4c Mon Sep 17 00:00:00 2001 From: capak07 <69026837+capak07@users.noreply.github.com> Date: Mon, 8 Apr 2024 00:28:42 -0300 Subject: [PATCH 3/3] Used batch job to delete --- lib/langchain/vectorsearch/weaviate.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/langchain/vectorsearch/weaviate.rb b/lib/langchain/vectorsearch/weaviate.rb index e2e60db85..32ae12e4c 100644 --- a/lib/langchain/vectorsearch/weaviate.rb +++ b/lib/langchain/vectorsearch/weaviate.rb @@ -71,13 +71,14 @@ def update_texts(texts:, ids:) end end + # Deletes a list of texts in the index + # @param ids The ids of texts to delete + # @return [Hash] The response from the server def remove_texts(ids:) - ids.map do |id| - client.objects.delete( - class_name: index_name, - id: id - ) - end + client.objects.batch_delete( + class_name: index_name, + where: "{ path: [\"__id\"], operator: ContainsAny, valueString: \"#{ids}\" }" + ) end # Create default schema