GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - pgvector/pgvector-c: pgvector examples for C

BranchesTags
Open more actions menu

Latest commit

 

History

31 Commits
31 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
examples
examples
 
 
test
test
 
 
.gitignore
.gitignore
 
 
CMakeLists.txt
CMakeLists.txt
 
 
LICENSE.txt
LICENSE.txt
 
 
README.md
README.md
 
 

Repository files navigation

pgvector-c

pgvector examples for C

Supports libpq

Build Status

Getting Started

Follow the instructions for your database library:

  • libpq

Or check out some examples:

  • Embeddings with OpenAI
  • Binary embeddings with Cohere
  • Bulk loading with COPY

libpq

Enable the extension

PGresult *res = PQexec(conn, "CREATE EXTENSION IF NOT EXISTS vector");

Create a table

PGresult *res = PQexec(conn, "CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3))");

Insert vectors

const char *paramValues[2] = {"[1,2,3]", "[4,5,6]"};
PGresult *res = PQexecParams(conn, "INSERT INTO items (embedding) VALUES ($1), ($2)", 2, NULL, paramValues, NULL, NULL, 0);

Get the nearest neighbors

const char *paramValues[1] = {"[3,1,2]"};
PGresult *res = PQexecParams(conn, "SELECT * FROM items ORDER BY embedding <-> $1 LIMIT 5", 1, NULL, paramValues, NULL, NULL, 0);

Add an approximate index

PGresult *res = PQexec(conn, "CREATE INDEX ON items USING hnsw (embedding vector_l2_ops)");
// or
PGresult *res = PQexec(conn, "CREATE INDEX ON items USING ivfflat (embedding vector_l2_ops) WITH (lists = 100)");

Use vector_ip_ops for inner product and vector_cosine_ops for cosine distance

See a full example

Contributing

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-c.git
cd pgvector-c
createdb pgvector_c_test
cmake -S . -B build
cmake --build build
build/test

To run an example:

cd examples/openai
createdb pgvector_example
cmake -S . -B build
cmake --build build
build/example

About

pgvector examples for C

Resources

Readme
MIT license

Security policy

Security policy
Activity
Custom properties

Stars

8 stars

Watchers

2 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.