langchain
7bc4e320 - core[patch]: improve performance of InMemoryVectorStore (#27538)

Commit
1 year ago
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 <eyurtsev@gmail.com>
Author
Parents
Loading