Harrison/svm speedup (#3195)

Co-authored-by: Lance Martin <122662504+PineappleExpress808@users.noreply.github.com>
This commit is contained in:
Harrison Chase 2023-04-19 20:14:01 -07:00 committed by GitHub
parent d6b2f2b9bd
commit e55db5841a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,6 +4,7 @@ https://github.com/karpathy/randomfun/blob/master/knn_vs_svm.ipynb"""
from __future__ import annotations
import concurrent.futures
from typing import Any, List, Optional
import numpy as np
@ -14,7 +15,8 @@ from langchain.schema import BaseRetriever, Document
def create_index(contexts: List[str], embeddings: Embeddings) -> np.ndarray:
return np.array([embeddings.embed_query(split) for split in contexts])
with concurrent.futures.ThreadPoolExecutor() as executor:
return np.array(list(executor.map(embeddings.embed_query, contexts)))
class SVMRetriever(BaseRetriever, BaseModel):