Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added remove_texts on base, elasticsearch, pgvector vectorsearch #525

Merged
merged 8 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/langchain/vectorsearch/pgvector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ def update_texts(texts:, ids:)
upsert_texts(texts: texts, ids: ids)
end

# Remove a list of texts from the index
# @param ids [Array<Integer>] The ids of the texts to remove from the index
# @return [Integer] The number of texts removed from the index
def remove_texts(ids:)
@db[table_name.to_sym].where(id: ids).delete
end

# Create default schema
def create_default_schema
db.run "CREATE EXTENSION IF NOT EXISTS vector"
Expand Down
30 changes: 30 additions & 0 deletions spec/langchain/vectorsearch/pgvector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,36 @@
end
end

describe "#remove_texts" do
before do
allow_any_instance_of(
OpenAI::Client
).to receive(:embeddings)
.with(
parameters: {
dimensions: 1536,
model: "text-embedding-3-small",
input: "Hello World"
}
)
.and_return({
"object" => "list",
"data" => [
{"embedding" => 1536.times.map { rand }}
]
})
end

it "removes texts" do
values = subject.add_texts(texts: ["Hello World", "Hello World"])
ids = values.flatten
expect(ids.length).to eq(2)

result = subject.remove_texts(ids: ids)
expect(result).to eq(2)
end
end

describe "#similarity_search" do
before do
allow_any_instance_of(
Expand Down