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 ) , [ Drizzle ORM] ( https://github.com/drizzle-team/drizzle-orm ) , and [ Bun SQL] ( https://bun.sh/docs/api/sql )
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 ) , [ deno-postgres ] ( https://github.com/denodrivers/postgres ) , 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+ - [ deno-postgres] ( #deno-postgres )
3132- [ Bun SQL] ( #bun-sql )
3233
3334Or check out some examples:
@@ -678,6 +679,52 @@ Also supports `innerProduct`, `cosineDistance`, `l1Distance`, `hammingDistance`,
678679
679680See a [ full example] ( tests/drizzle-orm.test.mjs )
680681
682+ ## deno-postgres
683+
684+ Import the library
685+
686+ ``` javascript
687+ import pgvector from ' npm:pgvector' ;
688+ ```
689+
690+ Enable the extension
691+
692+ ``` javascript
693+ await client .queryArray ` CREATE EXTENSION IF NOT EXISTS vector` ;
694+ ```
695+
696+ Create a table
697+
698+ ``` javascript
699+ await client .queryArray ` CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3))` ;
700+ ```
701+
702+ Insert a vector
703+
704+ ``` javascript
705+ const embedding = pgvector .toSql ([1 , 2 , 3 ]);
706+ await client .queryArray ` INSERT INTO items (embedding) VALUES (${ embedding} )` ;
707+ ```
708+
709+ Get the nearest neighbors to a vector
710+
711+ ``` javascript
712+ const embedding = pgvector .toSql ([1 , 2 , 3 ]);
713+ const { rows } = await client .queryArray ` SELECT * FROM items ORDER BY embedding <-> ${ embedding} LIMIT 5` ;
714+ ```
715+
716+ Add an approximate index
717+
718+ ``` javascript
719+ await client .queryArray ` CREATE INDEX ON items USING hnsw (embedding vector_l2_ops)` ;
720+ // or
721+ await client .queryArray ` CREATE INDEX ON items USING ivfflat (embedding vector_l2_ops) WITH (lists = 100)` ;
722+ ```
723+
724+ Use ` vector_ip_ops ` for inner product and ` vector_cosine_ops ` for cosine distance
725+
726+ See a [ full example] ( examples/deno/example.js )
727+
681728## Bun SQL
682729
683730Import the library
0 commit comments