--- license: mit --- # Static Embeddings using SQLiteVec - This repo contains [sentence-transformers/static-retrieval-mrl-en-v1](https://huggingface.co/sentence-transformers/static-retrieval-mrl-en-v1) model converted to [sqlite-vec](https://github.com/asg017/sqlite-vec) database. - This repo contains a Swift package that demonstrates how to use the [SQLiteVec](https://github.com/jkrukowski/SQLiteVec) to compute static embeddings. - This repo contains a benchmark that compares the performance of computing embeddings using [swift-embeddings](https://github.com/jkrukowski/swift-embeddings) and [SQLiteVec](https://github.com/jkrukowski/SQLiteVec). The sqlite-vec database was created using the following command: ```sql CREATE VIRTUAL TABLE embeddings USING vec0(embedding float[1024]) ``` and then the embeddings were inserted using the following command: ```sql INSERT INTO embeddings(rowid, embedding) VALUES (?, ?) ``` ## Benchmark To run the benchmark, execute the following command: ```bash cd EmbeddingsBenchmark swift package --disable-sandbox benchmark ``` ### Results ``` CoreML benchmark (count: 10) ╒═══════════════════════════════╤═════════╤═════════╤═════════╤═════════╤═════════╤═════════╤═════════╤═════════╕ │ Metric │ p0 │ p25 │ p50 │ p75 │ p90 │ p99 │ p100 │ Samples │ ╞═══════════════════════════════╪═════════╪═════════╪═════════╪═════════╪═════════╪═════════╪═════════╪═════════╡ │ Instructions (K) * │ 1712 │ 1779 │ 1779 │ 1791 │ 1792 │ 1805 │ 1899 │ 5136 │ ├───────────────────────────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤ │ Malloc (total) * │ 1131 │ 1132 │ 1132 │ 1132 │ 1132 │ 1132 │ 1139 │ 5136 │ ├───────────────────────────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤ │ Memory (resident peak) (M) │ 156 │ 158 │ 158 │ 159 │ 159 │ 159 │ 159 │ 5136 │ ├───────────────────────────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤ │ Throughput (# / s) (#) │ 11121 │ 9471 │ 9287 │ 8919 │ 8607 │ 7747 │ 5810 │ 5136 │ ├───────────────────────────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤ │ Time (total CPU) (μs) * │ 92 │ 107 │ 109 │ 114 │ 118 │ 131 │ 174 │ 5136 │ ├───────────────────────────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤ │ Time (wall clock) (μs) * │ 90 │ 106 │ 108 │ 112 │ 116 │ 129 │ 172 │ 5136 │ ╘═══════════════════════════════╧═════════╧═════════╧═════════╧═════════╧═════════╧═════════╧═════════╧═════════╛ CoreML benchmark (count: 1000) ╒═══════════════════════════════╤═════════╤═════════╤═════════╤═════════╤═════════╤═════════╤═════════╤═════════╕ │ Metric │ p0 │ p25 │ p50 │ p75 │ p90 │ p99 │ p100 │ Samples │ ╞═══════════════════════════════╪═════════╪═════════╪═════════╪═════════╪═════════╪═════════╪═════════╪═════════╡ │ Instructions (K) * │ 3320 │ 3422 │ 3467 │ 3516 │ 3545 │ 3566 │ 3640 │ 2698 │ ├───────────────────────────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤ │ Malloc (total) * │ 1131 │ 1132 │ 1132 │ 1132 │ 1132 │ 1132 │ 1140 │ 2698 │ ├───────────────────────────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤ │ Memory (resident peak) (M) │ 159 │ 162 │ 162 │ 162 │ 162 │ 162 │ 162 │ 2698 │ ├───────────────────────────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤ │ Throughput (# / s) (#) │ 4418 │ 4299 │ 4231 │ 4139 │ 3999 │ 3515 │ 2093 │ 2698 │ ├───────────────────────────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤ │ Time (total CPU) (μs) * │ 228 │ 234 │ 238 │ 243 │ 252 │ 287 │ 480 │ 2698 │ ├───────────────────────────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤ │ Time (wall clock) (μs) * │ 226 │ 233 │ 237 │ 242 │ 250 │ 285 │ 478 │ 2698 │ ╘═══════════════════════════════╧═════════╧═════════╧═════════╧═════════╧═════════╧═════════╧═════════╧═════════╛ CoreML benchmark (count: 100000) ╒═══════════════════════════════╤═════════╤═════════╤═════════╤═════════╤═════════╤═════════╤═════════╤═════════╕ │ Metric │ p0 │ p25 │ p50 │ p75 │ p90 │ p99 │ p100 │ Samples │ ╞═══════════════════════════════╪═════════╪═════════╪═════════╪═════════╪═════════╪═════════╪═════════╪═════════╡ │ Instructions (M) * │ 163 │ 163 │ 163 │ 163 │ 163 │ 168 │ 168 │ 20 │ ├───────────────────────────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤ │ Malloc (total) * │ 1131 │ 1131 │ 1131 │ 1132 │ 1133 │ 1139 │ 1139 │ 20 │ ├───────────────────────────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤ │ Memory (resident peak) (M) │ 566 │ 567 │ 567 │ 568 │ 568 │ 568 │ 568 │ 20 │ ├───────────────────────────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤ │ Throughput (# / s) (#) │ 21 │ 21 │ 21 │ 21 │ 21 │ 20 │ 20 │ 20 │ ├───────────────────────────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤ │ Time (total CPU) (ms) * │ 47 │ 48 │ 48 │ 48 │ 48 │ 50 │ 50 │ 20 │ ├───────────────────────────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤ │ Time (wall clock) (ms) * │ 47 │ 48 │ 48 │ 48 │ 48 │ 50 │ 50 │ 20 │ ╘═══════════════════════════════╧═════════╧═════════╧═════════╧═════════╧═════════╧═════════╧═════════╧═════════╛ SQLite benchmark (count: 10) ╒═══════════════════════════════╤═════════╤═════════╤═════════╤═════════╤═════════╤═════════╤═════════╤═════════╕ │ Metric │ p0 │ p25 │ p50 │ p75 │ p90 │ p99 │ p100 │ Samples │ ╞═══════════════════════════════╪═════════╪═════════╪═════════╪═════════╪═════════╪═════════╪═════════╪═════════╡ │ Instructions (M) * │ 103 │ 117 │ 122 │ 128 │ 132 │ 136 │ 140 │ 144 │ ├───────────────────────────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤ │ Malloc (total) * │ 99 │ 106 │ 106 │ 106 │ 106 │ 107 │ 107 │ 144 │ ├───────────────────────────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤ │ Memory (resident peak) (M) │ 15 │ 17 │ 19 │ 19 │ 19 │ 19 │ 19 │ 144 │ ├───────────────────────────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤ │ Throughput (# / s) (#) │ 186 │ 155 │ 147 │ 139 │ 132 │ 126 │ 126 │ 144 │ ├───────────────────────────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤ │ Time (total CPU) (μs) * │ 5382 │ 6451 │ 6779 │ 7180 │ 7582 │ 7922 │ 7932 │ 144 │ ├───────────────────────────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤ │ Time (wall clock) (μs) * │ 5380 │ 6443 │ 6779 │ 7180 │ 7574 │ 7918 │ 7930 │ 144 │ ╘═══════════════════════════════╧═════════╧═════════╧═════════╧═════════╧═════════╧═════════╧═════════╧═════════╛ SQLite benchmark (count: 1000) ╒═══════════════════════════════╤═════════╤═════════╤═════════╤═════════╤═════════╤═════════╤═════════╤═════════╕ │ Metric │ p0 │ p25 │ p50 │ p75 │ p90 │ p99 │ p100 │ Samples │ ╞═══════════════════════════════╪═════════╪═════════╪═════════╪═════════╪═════════╪═════════╪═════════╪═════════╡ │ Instructions (M) * │ 1517 │ 1572 │ 1599 │ 1611 │ 1618 │ 1618 │ 1618 │ 9 │ ├───────────────────────────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤ │ Malloc (total) * │ 6330 │ 6339 │ 6367 │ 6379 │ 6414 │ 6414 │ 6414 │ 9 │ ├───────────────────────────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤ │ Memory (resident peak) (M) │ 22 │ 23 │ 23 │ 23 │ 23 │ 23 │ 23 │ 9 │ ├───────────────────────────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤ │ Throughput (# / s) (#) │ 9 │ 8 │ 8 │ 8 │ 8 │ 8 │ 8 │ 9 │ ├───────────────────────────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤ │ Time (total CPU) (ms) * │ 114 │ 118 │ 120 │ 121 │ 121 │ 121 │ 121 │ 9 │ ├───────────────────────────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤ │ Time (wall clock) (ms) * │ 114 │ 118 │ 120 │ 121 │ 121 │ 121 │ 121 │ 9 │ ╘═══════════════════════════════╧═════════╧═════════╧═════════╧═════════╧═════════╧═════════╧═════════╧═════════╛ ```