pgvector 0.1.0 copy "pgvector: ^0.1.0" to clipboard
pgvector: ^0.1.0 copied to clipboard

pgvector support for Dart.

pgvector-dart #

pgvector support for Dart

Supports the postgres package

Build Status

Getting Started #

Run:

dart pub add pgvector

And follow the instructions for your database library:

postgres #

Import the library

import 'package:pgvector/pgvector.dart';

Enable the extension

await connection.execute("CREATE EXTENSION IF NOT EXISTS vector");

Create a table

await connection.execute(
    "CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3))");

Insert vectors

await connection.execute(
    "INSERT INTO items (embedding) VALUES (@a), (@b), (@c)",
    substitutionValues: {
      "a": pgvector.encode([1, 1, 1]),
      "b": pgvector.encode([2, 2, 2]),
      "c": pgvector.encode([1, 1, 2])
    });

Get the nearest neighbors

List<List<dynamic>> results = await connection.query(
    "SELECT id, embedding FROM items ORDER BY embedding <-> @embedding LIMIT 5",
    substitutionValues: {
      "embedding": pgvector.encode([1, 1, 1])
    });
for (final row in results) {
  print(row[0]);
  print(pgvector.decode(row[1]));
}

See a full example

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-dart.git
cd pgvector-dart
createdb pgvector_dart_test
dart test
2
likes
120
points
39
downloads

Publisher

verified publisherpgvector.com

Weekly Downloads

pgvector support for Dart.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

postgres

More

Packages that depend on pgvector