Skip to content

Commit eaa734a

Browse files
committed
Added FTS5 tests, formatting
1 parent 7dd6b5c commit eaa734a

File tree

2 files changed

+60
-18
lines changed

2 files changed

+60
-18
lines changed

Sources/SQLiteVecCLI/CLI.swift

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,66 @@
11
import Foundation
22
import SQLiteVec
33

4+
struct Item {
5+
let index: Int
6+
let vector: [Float]
7+
let title: String
8+
let content: String
9+
}
10+
411
@main
512
enum CLI {
613
static func main() async throws {
714
try SQLiteVec.initialize()
8-
let data: [(index: Int, vector: [Float], title: String, content: String)] = [
9-
(1, [0.1, 0.1, 0.1, 0.1], "Introduction to Machine Learning", "Machine learning is a subset of artificial intelligence..."),
10-
(2, [0.2, 0.2, 0.2, 0.2], "Deep Learning Basics", "Deep learning uses neural networks to learn from data..."),
11-
(3, [0.3, 0.3, 0.3, 0.3], "Natural Language Processing", "NLP combines linguistics and machine learning..."),
12-
(4, [0.4, 0.4, 0.4, 0.4], "Computer Vision", "Computer vision enables machines to understand visual data..."),
13-
(5, [0.5, 0.5, 0.5, 0.5], "Reinforcement Learning", "Reinforcement learning involves agents learning through interaction...")
15+
let data = [
16+
Item(
17+
index: 1,
18+
vector: [0.1, 0.1, 0.1, 0.1],
19+
title: "Introduction to Machine Learning",
20+
content: "Machine learning is a subset of artificial intelligence..."
21+
),
22+
Item(
23+
index: 2,
24+
vector: [0.2, 0.2, 0.2, 0.2],
25+
title: "Deep Learning Basics",
26+
content: "Deep learning uses neural networks to learn from data..."
27+
),
28+
Item(
29+
index: 3,
30+
vector: [0.3, 0.3, 0.3, 0.3],
31+
title: "Natural Language Processing",
32+
content: "NLP combines linguistics and machine learning..."
33+
),
34+
Item(
35+
index: 4,
36+
vector: [0.4, 0.4, 0.4, 0.4],
37+
title: "Computer Vision",
38+
content: "Computer vision enables machines to understand visual data..."
39+
),
40+
Item(
41+
index: 5,
42+
vector: [0.5, 0.5, 0.5, 0.5],
43+
title: "Reinforcement Learning",
44+
content: "Reinforcement learning involves agents learning through interaction..."
45+
),
1446
]
1547
let query: [Float] = [0.3, 0.3, 0.3, 0.3]
1648
let textQuery = "learning"
1749

1850
let db = try Database(.inMemory)
1951
try await db.execute("CREATE VIRTUAL TABLE vec_items USING vec0(embedding float[4])")
20-
try await db.execute("""
21-
CREATE VIRTUAL TABLE docs USING fts5(
22-
title,
23-
content,
24-
tokenize='porter'
25-
)
26-
""")
52+
try await db.execute(
53+
"""
54+
CREATE VIRTUAL TABLE docs USING fts5(
55+
title,
56+
content,
57+
tokenize='porter'
58+
)
59+
""")
2760
for row in data {
2861
try await db.execute(
2962
"""
30-
INSERT INTO vec_items(rowid, embedding)
63+
INSERT INTO vec_items(rowid, embedding)
3164
VALUES (?, ?)
3265
""",
3366
params: [row.index, row.vector]
@@ -42,10 +75,10 @@ enum CLI {
4275
}
4376
let result = try await db.query(
4477
"""
45-
SELECT rowid, distance
46-
FROM vec_items
47-
WHERE embedding MATCH ?
48-
ORDER BY distance
78+
SELECT rowid, distance
79+
FROM vec_items
80+
WHERE embedding MATCH ?
81+
ORDER BY distance
4982
LIMIT 3
5083
""",
5184
params: [query]

Tests/SQLiteVecTests/CoreTests.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,13 @@ final class CoreTests: XCTestCase {
1616
XCTAssertTrue(extensionNames.contains("vec_each"), "vec_each should be loaded")
1717
XCTAssertTrue(extensionNames.contains("vec0"), "vec0 should be loaded")
1818
}
19+
20+
func testCompileFlags() async throws {
21+
try SQLiteVec.initialize()
22+
let db = try Database(.inMemory)
23+
let result = try await db.query("PRAGMA compile_options")
24+
let compileFlags = result.compactMap { $0["compile_options"] as? String }
25+
26+
XCTAssertTrue(compileFlags.contains("ENABLE_FTS5"), "FTS5 should be enabled")
27+
}
1928
}

0 commit comments

Comments
 (0)