A high-performance Swift wrapper for sqlite-vec, providing type-safe vector similarity search and operations directly in SQLite.
- 🚀 High Performance: Leveraging SIMD optimizations and Metal acceleration for 3-5x speedup on batch operations
- 🔍 Vector Similarity Search: Support for cosine, L2, and Hamming distance metrics
- 📊 Multiple Vector Types: Float32, Int8, and binary bit vectors
- 🛡️ Type Safety: Full Swift type safety with compile-time guarantees
- 🔒 Enterprise Ready: Comprehensive audit logging and privacy features
- ⚡ Async/Await Support: Modern Swift concurrency with Swift 6 compatibility
- 📦 Easy Integration: Simple Package Manager integration with GRDB
Add SwiftSQLiteVec to your Package.swift dependencies:
dependencies: [
.package(url: "https://github.com/your-username/SwiftSQLiteVec.git", from: "0.0.5")
]import SwiftSQLiteVec
import GRDB
// Initialize database with vector extensions
let dbQueue = DatabaseQueue()
try dbQueue.setupSQLiteVec()
// Create a vector table
let vectorDef = VectorColumnDefinition(
name: "embedding",
dimensions: 1536,
elementType: .float32
)
try dbQueue.createVec0Table(
tableName: "documents",
columns: [vectorDef],
distanceMetric: .cosine
)
// Insert vectors with metadata
try dbQueue.insertDocument(
tableName: "documents",
id: "doc1",
embedding: [0.1, 0.2, 0.3, /* ... */],
metadata: ["title": "Hello World", "category": "greeting"]
)
// Perform similarity search
let results = try dbQueue.similaritySearch(
tableName: "documents",
queryVector: [0.15, 0.25, 0.35, /* ... */],
limit: 10,
threshold: 0.8
)
for result in results {
print("Document: \(result.id), Distance: \(result.distance)")
print("Metadata: \(result.metadata)")
}Comprehensive documentation is available in the Documentation.docc directory, including:
SwiftSQLiteVec provides significant performance optimizations:
- SIMD Acceleration: 3-5x speedup on batch operations using vDSP
- Metal Processing: GPU acceleration for large vector operations
- Zero-Copy Operations: Direct memory access for optimal performance
- Batch Operations: 10-50x speedup for bulk operations
Benchmarks show 10-100x performance improvement over equivalent Swift implementations due to optimized C code and zero-copy operations.
- Swift 5.9+
- macOS 12.0+, iOS 15.0+, or Linux
- GRDB 6.0+
We welcome contributions! Please see CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.
SwiftSQLiteVec is released under the MIT License.
- sqlite-vec - The underlying SQLite extension for vector operations
- GRDB - The excellent SQLite toolkit for Swift