Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core[patch]: improve performance of InMemoryVectorStore (#27538)
**Description:** We improve the performance of the InMemoryVectorStore. **Isue:** Originally, similarity was computed document by document: ``` for doc in self.store.values(): vector = doc["vector"] similarity = float(cosine_similarity([embedding], [vector]).item(0)) ``` This is inefficient and does not make use of numpy vectorization. This PR computes the similarity in one vectorized go: ``` docs = list(self.store.values()) similarity = cosine_similarity([embedding], [doc["vector"] for doc in docs]) ``` **Dependencies:** None **Twitter handle:** @b12_consulting, @Vincent_Min --------- Co-authored-by: Eugene Yurtsev <[email protected]>
- Loading branch information