Skip to content

finnvoor/SQLiteVec.swift

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SQLiteVec.swift

A fork of SQLite.swift with sqlite-vec enabled.

let connection = try Connection(.inMemory)

try connection.prepare(
    """
    CREATE VIRTUAL TABLE IF NOT EXISTS embeddings USING vec0(
      id INTEGER PRIMARY KEY,
      embedding float[4]
    );
    """
).run()

let insert = try connection.prepare("""
    INSERT INTO embeddings(id, embedding)
    VALUES (?, ?)
""")
try insert.run(0, [0.0, 0.0, 1.0, 0.0])

let nearest = try connection.prepare("""
    SELECT id, distance
    FROM embeddings
    WHERE embedding MATCH ?
    ORDER BY distance
    LIMIT 20
""").run([0.0, 1.0, 0.0, 1.0])
// (0, [0.0, 0.0, 1.0, 0.0])

License

Any code not covered by the existing SQLite.swift or sqlite-vec licenses is CC0 licensed.

About

A type-safe, Swift-language layer over SQLite3 + sqlite-vec.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 94.8%
  • Swift 5.2%