Skip to content

pgvector/pgvector-cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pgvector-cpp

pgvector support for C++

Supports libpqxx

Build Status

Getting Started

Run

git clone https://github.com/ankane/pgvector-cpp.git
cd pgvector-cpp && mkdir build && cd build
cmake ..
make install # may need sudo

Include 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

Reference

Convert a vector to a std::vector<float>

auto float_vec = static_cast<std::vector<float>>(factors);

History

View the changelog

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

To get started with development:

git clone https://github.com/ankane/pgvector-cpp.git
cd pgvector-cpp
createdb pgvector_cpp_test
g++ -std=c++20 -lpqxx -lpq -o test/pqxx test/pqxx_test.cpp
test/pqxx

About

pgvector support for C++

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published