Skip to content

Commit

Permalink
Added HalfVector class
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Sep 10, 2024
1 parent a0ae84d commit 977971b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## 0.1.1 (unreleased)

- Added `Vector` class
- Added `Vector` and `HalfVector` classes

## 0.1.0 (2023-10-17)

Expand Down
14 changes: 14 additions & 0 deletions lib/halfvec.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class HalfVector {
final List<double> vec;

const HalfVector(this.vec);

List<double> toList() {
return vec;
}

@override
String toString() {
return vec.toString();
}
}
3 changes: 3 additions & 0 deletions lib/pgvector.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import 'dart:convert';
import 'dart:typed_data';

import 'halfvec.dart';
import 'vector.dart';

export 'halfvec.dart' show HalfVector;
export 'vector.dart' show Vector;

class Pgvector {
Expand Down
10 changes: 7 additions & 3 deletions test/postgres_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ void main() {
await connection.execute("DROP TABLE IF EXISTS items");

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

await connection.execute(
Sql.named("INSERT INTO items (embedding) VALUES (@a), (@b), (@c)"),
Sql.named(
"INSERT INTO items (embedding, half_embedding) VALUES (@a, @d), (@b, @e), (@c, @f)"),
parameters: {
"a": Vector([1, 1, 1]).toString(),
"b": Vector([2, 2, 2]).toString(),
"c": Vector([1, 1, 2]).toString()
"c": Vector([1, 1, 2]).toString(),
"d": HalfVector([1, 1, 1]).toString(),
"e": HalfVector([2, 2, 2]).toString(),
"f": HalfVector([1, 1, 2]).toString()
});

List<List<dynamic>> results = await connection.execute(
Expand Down

0 comments on commit 977971b

Please sign in to comment.