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

Adding Listing all vectors functionality #38

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ GEM
PLATFORMS
arm64-darwin-21
arm64-darwin-22
arm64-darwin-23
x86_64-darwin-21
x86_64-linux

Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ index.describe_index_stats(
)
```

List all vectors in an index.
```ruby
pinecone = Pinecone::Client.new
index = pinecone.index("example-index")
index.list(prefix: "document1#", namespace: "example-namespace")
```

### Filtering queries

Add a `filter` option to apply filters to your query. You can use vector metadata to limit your search. See [metadata filtering](https://www.pinecone.io/docs/metadata-filtering/) in Pinecode documentation.
Expand Down
13 changes: 12 additions & 1 deletion lib/pinecone/vector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def delete(namespace: "", ids: [], delete_all: false, filter: {})
deleteAll: delete_all,
filter: filter
}

inputs.delete(:filter) if delete_all || ids.any?
payload = options.merge(body: inputs.to_json)
self.class.post("#{@base_uri}/vectors/delete", payload)
Expand Down Expand Up @@ -70,6 +69,18 @@ def describe_index_stats(filter: {})
self.class.post("#{@base_uri}/describe_index_stats", payload)
end

def list(namespace: "", prefix: nil, limit: 100, pagination_token: nil)
query_params = {
namespace: namespace,
limit: limit
}
query_params[:prefix] = prefix if prefix
query_params[:paginationToken] = pagination_token if pagination_token

query_string = URI.encode_www_form(query_params)
self.class.get("#{@base_uri}/vectors/list?#{query_string}", options)
end

def options
{
headers: @headers
Expand Down
2 changes: 1 addition & 1 deletion lib/pinecone/vector/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def to_filter(input)
def self.new(input)
validation = FilterContract.new.call(input)
if validation.success?
super(input)
super
else
raise ArgumentError.new(validation.errors.to_h.inspect)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/pinecone/vector/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class QueryContract < Dry::Validation::Contract
def self.new(input)
validation = QueryContract.new.call(input)
if validation.success?
super(input)
super
else
raise ArgumentError.new(validation.errors.to_h.inspect)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/pinecone/vector/sparse_vector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SparseVectorContract < Dry::Validation::Contract
def self.new(input)
validation = SparseVectorContract.new.call(input)
if validation.success?
super(input)
super
else
raise ArgumentError.new(validation.errors.to_h.inspect)
end
Expand Down
28 changes: 16 additions & 12 deletions spec/cassettes/Pinecone_Client/_index/allows_multiple_indices.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading