pgvector-node  by pgvector

Node.js library for pgvector support

created 4 years ago
399 stars

Top 73.5% on sourcepulse

GitHubView on GitHub
Project Summary

This library provides Node.js, Deno, and Bun bindings for the pgvector PostgreSQL extension, enabling efficient storage and similarity search of vector embeddings. It supports a wide range of popular ORMs and database clients, simplifying integration for developers building AI-powered applications.

How It Works

The library acts as a bridge between JavaScript/TypeScript environments and the pgvector extension's SQL capabilities. It offers helper functions to register custom vector types with database clients, convert JavaScript arrays to pgvector's SQL format, and construct SQL queries for common operations like creating tables with vector columns, inserting vectors, and performing nearest neighbor searches using various distance metrics (L2, cosine, inner product). It also facilitates the creation of approximate nearest neighbor (ANN) indexes like HNSW and IVFFlat.

Quick Start & Requirements

  • Installation: npm install pgvector
  • Prerequisites: PostgreSQL with the pgvector extension installed.
  • Usage: Import the relevant module for your ORM/client (e.g., pgvector/pg, pgvector/knex) and follow the provided examples for enabling extensions, creating tables, inserting data, and querying.
  • Examples: Embeddings with OpenAI, Hybrid search

Highlighted Details

  • Broad ORM support: node-postgres, Knex.js, Objection.js, Kysely, Sequelize, pg-promise, Prisma, Postgres.js, Slonik, TypeORM, MikroORM, Drizzle ORM, Bun SQL.
  • Supports multiple distance metrics: L2, inner product, cosine, L1, Hamming, Jaccard.
  • Facilitates creation of ANN indexes (HNSW, IVFFlat).
  • Includes examples for various use cases like OpenAI embeddings, hybrid search, and recommendations.
  • Supports sparse vectors.

Maintenance & Community

  • Active development with contributions from multiple developers.
  • Development setup includes running tests via npm test.
  • Examples are provided for common use cases.

Licensing & Compatibility

  • MIT License.
  • Compatible with commercial and closed-source applications.

Limitations & Caveats

  • Prisma's migrate dev does not support pgvector indexes directly, requiring manual SQL for index creation.
Health Check
Last commit

2 weeks ago

Responsiveness

1 day

Pull Requests (30d)
0
Issues (30d)
0
Star History
28 stars in the last 90 days

Explore Similar Projects

Feedback? Help us improve.