pgvector support for C++
Supports libpqxx
Run
git clone https://github.com/pgvector/pgvector-cpp.git cd pgvector-cpp && mkdir build &&cd build cmake .. make install # may need sudoInclude the header
#include<pgvector/pqxx.hpp>Insert a vector
auto factors = pgvector::Vector({1, 2, 3}); W.exec_params("INSERT INTO items (factors) VALUES ($1)", factors);Get the nearest neighbors
pqxx::result R{W.exec_params("SELECT * FROM items ORDER BY factors <-> $1 LIMIT 5", factors)};Retrieve a vector
auto row = W.exec1("SELECT factors FROM items LIMIT 1"); auto factors = row[0].as<pgvector::Vector>();Use std::optional<pgvector::Vector> if the value could be NULL
Convert a vector to a std::vector<float>
auto float_vec = static_cast<std::vector<float>>(factors);View the changelog
Everyone is encouraged to help improve this project. Here are a few ways you can help:
- Report bugs
- Fix bugs and submit pull requests
- Write, clarify, or fix documentation
- Suggest or add new features
To get started with development:
git clone https://github.com/pgvector/pgvector-cpp.git cd pgvector-cpp createdb pgvector_cpp_test g++ -std=c++17 -o test/pqxx test/pqxx_test.cpp -lpqxx -lpq test/pqxx