Socket
Book a DemoInstallSign in
Socket

pgvector-ts

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pgvector-ts

pgvector support for Node.js and typescript

latest
Source
npmnpm
Version
0.1.2
Version published
Maintainers
1
Created
Source

pgvector-ts

pgvector support for Node.js Typescript

Supports Sequelize, node-postgres, and pg-promise

Build Status

Installation

Run:

npm install pgvector-ts

And follow the instructions for your database library:

Sequelize

Register the type

const { Sequelize } = require('sequelize-typescript');
const pgvector = require('pgvector-ts/sequelize');

pgvector.registerType(Sequelize);

Add a vector field

Item.init({
  embedding: {
    type: DataTypes.VECTOR(3)
  }
}, ...);

Insert a vector

await Item.create({embedding: [1, 2, 3]});

Get the nearest neighbors to a vector

const items = await Item.findAll({
  order: [sequelize.literal(`embedding <-> '[1, 2, 3]'`)],
  limit: 5
});

node-postgres

Register the type

const pgvector = require('pgvector-ts/pg');

await pgvector.registerType(client);

Insert a vector

const embedding = [1, 2, 3];
await client.query('INSERT INTO items (embedding) VALUES ($1)', [pgvector.toSql(embedding)]);

Get the nearest neighbors to a vector

const result = await client.query('SELECT * FROM items ORDER BY embedding <-> $1 LIMIT 5', [pgvector.toSql(embedding)]);

pg-promise

Register the type

const pgvector = require('pgvector/pg');

const initOptions = {
  async connect(client, dc, useCount) {
    await pgvector.registerType(client);
  }
};
const pgp = require('pg-promise')(initOptions);

Insert a vector

const embedding = [1, 2, 3];
await db.none('INSERT INTO items (embedding) VALUES ($1)', [pgvector.toSql(embedding)]);

Get the nearest neighbors to a vector

const result = await db.any('SELECT * FROM items ORDER BY embedding <-> $1 LIMIT 5', [pgvector.toSql(embedding)]);

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/pgvector/pgvector-node.git
cd pgvector-node
npm install
createdb pgvector_node_test
npm test

Keywords

sequelize

FAQs

Package last updated on 16 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.