mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-19 13:23:35 +00:00
Harrison/svm speedup (#3195)
Co-authored-by: Lance Martin <122662504+PineappleExpress808@users.noreply.github.com>
This commit is contained in:
parent
d6b2f2b9bd
commit
e55db5841a
@ -4,6 +4,7 @@ https://github.com/karpathy/randomfun/blob/master/knn_vs_svm.ipynb"""
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import concurrent.futures
|
||||||
from typing import Any, List, Optional
|
from typing import Any, List, Optional
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
@ -14,7 +15,8 @@ from langchain.schema import BaseRetriever, Document
|
|||||||
|
|
||||||
|
|
||||||
def create_index(contexts: List[str], embeddings: Embeddings) -> np.ndarray:
|
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):
|
class SVMRetriever(BaseRetriever, BaseModel):
|
||||||
|
Loading…
Reference in New Issue
Block a user