Cppinecone
A C++ client for the Pinecone vector database
url_builder.hpp
Go to the documentation of this file.
1 #pragma once
7 #include <map>
8 #include <sstream>
9 #include <string>
10 #include <string_view>
11 
14 
15 namespace pinecone::net
16 {
20 struct url_builder {
21  url_builder() = default;
27  explicit url_builder(std::string environment) noexcept : _environment(std::move(environment))
28  {
30  oss << "https://controller." << _environment << ".pinecone.io";
31  _controller_prefix = oss.str();
32  }
33 
43  auto set_metadata(types::api_metadata metadata) noexcept { _metadata = std::move(metadata); }
44 
48  [[nodiscard]] auto prefix() const noexcept -> std::string_view { return _controller_prefix; }
49 
56  template <domain::operation_type op>
57  [[nodiscard]] auto build() const noexcept -> std::string
58  {
59  if constexpr (domain::op_api_type(op) == domain::api_type::controller) {
60  return _controller_prefix + domain::op_url_fragment(op);
61  }
62  }
63 
71  template <domain::operation_type op>
72  [[nodiscard]] auto build(std::string_view index_name) const noexcept -> std::string
73  {
74  if constexpr (domain::op_api_type(op) == domain::api_type::service) {
76  oss << "https://" << index_name << "-" << _metadata.md_project_name() << ".svc."
77  << _environment << ".pinecone.io" << domain::op_url_fragment(op);
78  return oss.str();
79  }
80  }
81 
82  private:
83  std::string _environment;
84  std::string _controller_prefix;
85  types::api_metadata _metadata;
86 };
87 } // namespace pinecone::net
Metadata required by the Pinecone API.
T move(T... args)
STL namespace.
Operations made available by the Pinecone API.
T str(T... args)
Constructs Pinecone API URLs.
Definition: url_builder.hpp:20
url_builder(std::string environment) noexcept
Construct a new url builder object.
Definition: url_builder.hpp:27
auto set_metadata(types::api_metadata metadata) noexcept
Set the API metadata.
Definition: url_builder.hpp:43
auto build(std::string_view index_name) const noexcept -> std::string
Constructs a URL for a specific operation_type requiring an index name.
Definition: url_builder.hpp:72
auto prefix() const noexcept -> std::string_view
Definition: url_builder.hpp:48
auto build() const noexcept -> std::string
Constructs a URL for a specific operation_type.
Definition: url_builder.hpp:57
Pinecone API metadata.
auto md_project_name() const noexcept -> std::string const &