22
33[ pgvector] ( https://github.com/pgvector/pgvector ) support for Node.js, Deno, and Bun (and TypeScript)
44
5- Supports [ node-postgres] ( https://github.com/brianc/node-postgres ) , [ Knex.js] ( https://github.com/knex/knex ) , [ Objection.js] ( https://github.com/vincit/objection.js ) , [ Kysely] ( https://github.com/kysely-org/kysely ) , [ Sequelize] ( https://github.com/sequelize/sequelize ) , [ pg-promise] ( https://github.com/vitaly-t/pg-promise ) , [ Prisma] ( https://github.com/prisma/prisma ) , [ Postgres.js] ( https://github.com/porsager/postgres ) , [ Slonik] ( https://github.com/gajus/slonik ) , [ TypeORM] ( https://github.com/typeorm/typeorm ) , [ MikroORM] ( https://github.com/mikro-orm/mikro-orm ) , and [ Drizzle ORM] ( https://github.com/drizzle-team/drizzle-orm )
5+ Supports [ node-postgres] ( https://github.com/brianc/node-postgres ) , [ Knex.js] ( https://github.com/knex/knex ) , [ Objection.js] ( https://github.com/vincit/objection.js ) , [ Kysely] ( https://github.com/kysely-org/kysely ) , [ Sequelize] ( https://github.com/sequelize/sequelize ) , [ pg-promise] ( https://github.com/vitaly-t/pg-promise ) , [ Prisma] ( https://github.com/prisma/prisma ) , [ Postgres.js] ( https://github.com/porsager/postgres ) , [ Slonik] ( https://github.com/gajus/slonik ) , [ TypeORM] ( https://github.com/typeorm/typeorm ) , [ MikroORM] ( https://github.com/mikro-orm/mikro-orm ) , [ Drizzle ORM] ( https://github.com/drizzle-team/drizzle-orm ) , and [ Bun SQL ] ( https://bun.sh/docs/api/sql )
66
77[ ![ Build Status] ( https://github.com/pgvector/pgvector-node/actions/workflows/build.yml/badge.svg )] ( https://github.com/pgvector/pgvector-node/actions )
88
@@ -28,6 +28,7 @@ And follow the instructions for your database library:
2828- [ TypeORM] ( #typeorm )
2929- [ MikroORM] ( #mikroorm )
3030- [ Drizzle ORM] ( #drizzle-orm )
31+ - [ Bun SQL] ( #bun-sql )
3132
3233Or check out some examples:
3334
@@ -678,6 +679,55 @@ Also supports `innerProduct`, `cosineDistance`, `l1Distance`, `hammingDistance`,
678679
679680See a [ full example] ( tests/drizzle-orm.test.mjs )
680681
682+ ## Bun SQL
683+
684+ Import the library
685+
686+ ``` javascript
687+ import pgvector from ' pgvector' ;
688+ ```
689+
690+ Enable the extension
691+
692+ ``` javascript
693+ await sql ` CREATE EXTENSION IF NOT EXISTS vector` ;
694+ ```
695+
696+ Create a table
697+
698+ ``` javascript
699+ await sql ` CREATE TABLE items (id bigserial PRIMARY KEY , embedding vector(3 ))` ;
700+ ```
701+
702+ Insert vectors
703+
704+ ``` javascript
705+ const newItems = [
706+ {embedding: pgvector .toSql ([1 , 2 , 3 ])},
707+ {embedding: pgvector .toSql ([4 , 5 , 6 ])}
708+ ];
709+ await sql ` INSERT INTO items (embedding) ${ sql (newItems)} ` ;
710+ ```
711+
712+ Get the nearest neighbors to a vector
713+
714+ ``` javascript
715+ const embedding = pgvector .toSql ([1 , 2 , 3 ]);
716+ const items = await sql ` SELECT * FROM items ORDER BY embedding < - > ${ embedding} LIMIT 5 ` .values ();
717+ ```
718+
719+ Add an approximate index
720+
721+ ``` javascript
722+ await sql ` CREATE INDEX ON items USING hnsw (embedding vector_l2_ops)` ;
723+ // or
724+ await sql ` CREATE INDEX ON items USING ivfflat (embedding vector_l2_ops) WITH (lists = 100 )` ;
725+ ```
726+
727+ Use ` vector_ip_ops ` for inner product and ` vector_cosine_ops ` for cosine distance
728+
729+ See a [ full example] ( examples/bun/example.js )
730+
681731## History
682732
683733View the [ changelog] ( https://github.com/pgvector/pgvector-node/blob/master/CHANGELOG.md )
0 commit comments