#pragma once // Pinecone: control plane (indexes, collections, backups), data plane // (upsert, query, fetch, list, delete, namespaces, stats) and inference // (embed, rerank). API version 2026-07. The data plane lives on the host of an // index, so a Pinecone object is built with that host (empty = control plane // and inference only). Implements Embedder and Reranker through the hosted // inference models. #include #include #include "vendors/retrieval/provider.h" #include "vendors/retrieval/seams.h" namespace molo::retrieval { const CallTable& pinecone_calls(); struct PineconeVector { std::string id; std::vector values; Json metadata; // null = none }; struct PineconeMatch { std::string id; double score = 0; std::vector values; Json metadata; }; struct PineconeQuery { std::vector vector; // or `id` std::string id; int top_k = 10; std::string ns; // namespace; empty = the default namespace Json filter; // null = none bool include_values = false; bool include_metadata = true; }; struct PineconePage { std::vector ids; std::string next_token; // empty = last page bool truncated = false; // the page walk hit the cap }; class Pinecone : public Provider, public Embedder, public Reranker { public: static constexpr const char* kKeyEnv = "PINECONE_API_KEY"; static constexpr const char* kControlUrl = "https://api.pinecone.io"; static constexpr const char* kApiVersion = "2026-07"; static constexpr const char* kDefaultEmbedModel = "multilingual-e5-large"; static constexpr const char* kDefaultRerankModel = "bge-reranker-v2-m3"; static constexpr std::size_t kFetchIdsPerCall = 100; // ids travel in the URL static llm::ApiClientConfig config(); // index_host: the `host` field of describe_index, e.g. "my-index-abc.svc.pinecone.io". static Pinecone from_env(const std::string& index_host = ""); static Pinecone with(const TransportFactory& factory, std::string key, const std::string& index_host = ""); explicit Pinecone(std::shared_ptr gateway) : Provider(std::move(gateway)) {} std::string provider() const override { return "pinecone"; } EmbedResult embed(const EmbedRequest& request) override; RerankResult rerank(const RerankRequest& request) override; // Control plane Json list_indexes(); Json describe_index(const std::string& name); // A dense-vector index on Pinecone managed infrastructure. Json create_index(const std::string& name, int dimension, const std::string& metric, const std::string& cloud, const std::string& region); Json configure_index(const std::string& name, const Json& body); // Destructive. Json delete_index(const std::string& name); Json list_collections(); Json describe_collection(const std::string& name); Json create_collection(const std::string& name, const std::string& source_index); Json delete_collection(const std::string& name); // destructive Json list_backups(const std::string& index_name); Json create_backup(const std::string& index_name, const std::string& name, const std::string& description); Json describe_backup(const std::string& backup_id); Json delete_backup(const std::string& backup_id); // destructive // Data plane (needs the index host) Json upsert(const std::vector& vectors, const std::string& ns); std::vector query(const PineconeQuery& query); Json fetch(const std::vector& ids, const std::string& ns); PineconePage list(const std::string& prefix, const std::string& ns, int limit, const std::string& token); Json stats(const Json& filter); Json list_namespaces(int limit, const std::string& token); Json describe_namespace(const std::string& ns); // Destructive. Json delete_ids(const std::vector& ids, const std::string& ns); Json delete_all(const std::string& ns); Json delete_by_filter(const Json& filter, const std::string& ns); Json delete_namespace(const std::string& ns); static EmbedResult parse_embeddings(const Json& doc); static RerankResult parse_rerank(const Json& doc); static std::vector parse_matches(const Json& doc); static PineconePage parse_list(const Json& doc); static Json vector_json(const PineconeVector& v); }; } // namespace molo::retrieval