# 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}"