Skip to content

Commit 25d5dda

Browse files
committed
Started package
1 parent 2efef24 commit 25d5dda

File tree

8 files changed

+81
-2
lines changed

8 files changed

+81
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 0.1.0 (unreleased)
2+
3+
- First release

Sources/Pgvector/HalfVector.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#if canImport(PostgresClientKit)
2+
import PostgresClientKit
3+
#endif
4+
5+
struct HalfVector: Equatable {
6+
var value: [Float16]
7+
8+
init(_ value: [Float16]) {
9+
self.value = value
10+
}
11+
12+
static func == (lhs: HalfVector, rhs: HalfVector) -> Bool {
13+
return lhs.value == rhs.value
14+
}
15+
}
16+
17+
#if canImport(PostgresClientKit)
18+
extension HalfVector: PostgresValueConvertible {
19+
public var postgresValue: PostgresValue {
20+
return PostgresValue(String(describing: value))
21+
}
22+
}
23+
#endif

Sources/Pgvector/Pgvector.swift

Whitespace-only changes.

Sources/Pgvector/Vector.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#if canImport(PostgresClientKit)
2+
import PostgresClientKit
3+
#endif
4+
5+
struct Vector: Equatable {
6+
var value: [Float]
7+
8+
init(_ value: [Float]) {
9+
self.value = value
10+
}
11+
12+
static func == (lhs: Vector, rhs: Vector) -> Bool {
13+
return lhs.value == rhs.value
14+
}
15+
}
16+
17+
#if canImport(PostgresClientKit)
18+
extension Vector: PostgresValueConvertible {
19+
public var postgresValue: PostgresValue {
20+
return PostgresValue(String(describing: value))
21+
}
22+
}
23+
#endif
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import Foundation
2+
import Testing
3+
@testable import Pgvector
4+
5+
final class HalfVectorTests {
6+
@Test func equatable() {
7+
let a = HalfVector([1, 2, 3])
8+
let b = HalfVector([1, 2, 3])
9+
let c = HalfVector([1, 2, 4])
10+
#expect(a == a)
11+
#expect(a == b)
12+
#expect(a != c)
13+
}
14+
}

Tests/PgvectorTests/PostgresClientKitTests.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Foundation
22
import PostgresClientKit
33
import Testing
4+
@testable import Pgvector
45

56
final class PostgresClientKitTests {
67
@Test func example() throws {
@@ -26,11 +27,11 @@ final class PostgresClientKitTests {
2627

2728
text = "INSERT INTO items (embedding) VALUES ($1), ($2), ($3)"
2829
statement = try connection.prepareStatement(text: text)
29-
try statement.execute(parameterValues: ["[1,1,1]", "[2,2,2]", "[1,1,2]"])
30+
try statement.execute(parameterValues: [Vector([1, 1, 1]), Vector([2, 2, 2]), Vector([1, 1, 2])])
3031

3132
text = "SELECT * FROM items ORDER BY embedding <-> $1 LIMIT 5"
3233
statement = try connection.prepareStatement(text: text)
33-
let cursor = try statement.execute(parameterValues: ["[1,1,1]"])
34+
let cursor = try statement.execute(parameterValues: [Vector([1, 1, 1])])
3435

3536
for row in cursor {
3637
let columns = try row.get().columns

Tests/PgvectorTests/PostgresNIOTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Foundation
22
import PostgresNIO
33
import Testing
4+
@testable import Pgvector
45

56
final class PostgresNIOTests {
67
@Test func example() async throws {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import Foundation
2+
import Testing
3+
@testable import Pgvector
4+
5+
final class VectorTests {
6+
@Test func equatable() {
7+
let a = Vector([1, 2, 3])
8+
let b = Vector([1, 2, 3])
9+
let c = Vector([1, 2, 4])
10+
#expect(a == a)
11+
#expect(a == b)
12+
#expect(a != c)
13+
}
14+
}

0 commit comments

Comments
 (0)