Skip to content

Commit

Permalink
Add Milvus#remove_texts() method
Browse files Browse the repository at this point in the history
  • Loading branch information
andreibondarev committed Jul 1, 2024
1 parent a6a13a7 commit 0d79e83
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/langchain/vectorsearch/milvus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ def add_texts(texts:)
)
end

# Deletes a list of texts in the index
#
# @param ids [Array<Integer>] 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
Expand Down Expand Up @@ -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"},
Expand Down
12 changes: 12 additions & 0 deletions spec/langchain/vectorsearch/milvus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0d79e83

Please sign in to comment.