Commit 4dbc069
committed
fix(vector): Correct FAISS index training and search locking
This commit addresses two critical issues in the `faiss_manager.rs` file to improve correctness and performance.
First, it fixes a bug where the FAISS index was not being trained before vectors were added. This is a required step for many index types (e.g., IVF) and would lead to runtime crashes. The code now checks if the index is trained and, if not, trains it on the first batch of vectors that meets the training threshold.
Second, it resolves a performance bottleneck in concurrent search scenarios. The `search` function was taking a write lock on the index, which unnecessarily serialized all search operations. This has been changed to a read lock, allowing for concurrent searches and significantly improving throughput in multi-threaded environments.1 parent bac41e8 commit 4dbc069
1 file changed
+14
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | | - | |
79 | 78 | | |
80 | 79 | | |
81 | 80 | | |
82 | 81 | | |
83 | 82 | | |
84 | | - | |
85 | 83 | | |
86 | 84 | | |
87 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
88 | 97 | | |
89 | 98 | | |
90 | 99 | | |
| |||
119 | 128 | | |
120 | 129 | | |
121 | 130 | | |
122 | | - | |
| 131 | + | |
| 132 | + | |
123 | 133 | | |
124 | | - | |
| 134 | + | |
125 | 135 | | |
126 | 136 | | |
127 | 137 | | |
| |||
0 commit comments