Sha256: d5bafbf0ac002d30b7737534c9529e64c14e626d0f77a14460461c2c545a474e

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true
require 'ruby/openai_pinecone'

# Configure the gem with your credentials
Ruby::OpenaiPinecone.configure do |config|
  config.openai_api_key = "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"
  config.pinecone_api_key = "c008ac71-7f10-4b23-8cf5-4b8bae5242a5"
  config.pinecone_upsert_endpoint = "https://catalog-aff3af1.svc.us-west1-gcp-free.pinecone.io/vectors/upsert"
  config.pinecone_query_endpoint = "https://catalog-aff3af1.svc.us-west1-gcp-free.pinecone.io/query"
end

# Generate a vector for the input text
text = "Uber Eats is an American online food ordering and delivery platform launched by Uber in 2014 and based in San Francisco, California. Users can read menus, reviews and ratings, order food from participating restaurants, and pay for their orders with Uber Eats."
vector = Ruby::OpenaiPinecone::Embeddings.generate(text)
puts "Generated vector: #{vector}"

# Upsert the vector to Pinecone
# id = "7"
# success = Ruby::OpenaiPinecone::Client.upsert(id, vector)
# puts "Upsert successful" if success

# Query the existing vectors
query_result = Ruby::OpenaiPinecone::Client.query(text)
ids_and_scores = query_result["matches"].map { |match| { id: match["id"], score: match["score"] } }
puts "Query result: #{ids_and_scores}"

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruby-openai-pinecone-0.1.0 examples/test.rb