Skip to content

Commit

Permalink
Updated test to use Vector class
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Sep 10, 2024
1 parent d0e0f27 commit a0ae84d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.1 (unreleased)

- Added `Vector` class

## 0.1.0 (2023-10-17)

- First release
1 change: 1 addition & 0 deletions lib/pgvector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:convert';
import 'dart:typed_data';

import 'vector.dart';
export 'vector.dart' show Vector;

class Pgvector {
const Pgvector();
Expand Down
10 changes: 5 additions & 5 deletions test/postgres_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ void main() {
await connection.execute(
Sql.named("INSERT INTO items (embedding) VALUES (@a), (@b), (@c)"),
parameters: {
"a": pgvector.encode([1, 1, 1]),
"b": pgvector.encode([2, 2, 2]),
"c": pgvector.encode([1, 1, 2])
"a": Vector([1, 1, 1]).toString(),
"b": Vector([2, 2, 2]).toString(),
"c": Vector([1, 1, 2]).toString()
});

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

await connection
Expand Down

0 comments on commit a0ae84d

Please sign in to comment.