mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-04 04:28:58 +00:00
community[patch]: vectorstores
import update (#21169)
Issue: we have several helper functions to import third-party libraries like lancedb.import_lancedb in [community.vectorstores](https://api.python.langchain.com/en/latest/vectorstores/langchain_community.vectorstores.lancedb.import_lancedb.html#langchain_community.vectorstores.lancedb.import_lancedb). And we have core.utils.utils.guard_import that works exactly for this purpose. The import_<package> functions work inconsistently and rather be private functions. Change: replaced these functions with the guard_import function. Related to #21133
This commit is contained in:
@@ -7,20 +7,13 @@ from typing import Any, Iterable, List, Optional
|
||||
|
||||
from langchain_core.documents import Document
|
||||
from langchain_core.embeddings import Embeddings
|
||||
from langchain_core.utils import guard_import
|
||||
from langchain_core.vectorstores import VectorStore
|
||||
|
||||
|
||||
def import_lancedb() -> Any:
|
||||
"""Import lancedb package."""
|
||||
|
||||
try:
|
||||
import lancedb
|
||||
except ImportError as e:
|
||||
raise ImportError(
|
||||
"Could not import pinecone lancedb package. "
|
||||
"Please install it with `pip install lancedb`."
|
||||
) from e
|
||||
return lancedb
|
||||
return guard_import("lancedb")
|
||||
|
||||
|
||||
class LanceDB(VectorStore):
|
||||
@@ -64,7 +57,7 @@ class LanceDB(VectorStore):
|
||||
mode: Optional[str] = "overwrite",
|
||||
):
|
||||
"""Initialize with Lance DB vectorstore"""
|
||||
lancedb = import_lancedb()
|
||||
lancedb = guard_import("lancedb")
|
||||
self._embedding = embedding
|
||||
self._vector_key = vector_key
|
||||
self._id_key = id_key
|
||||
|
Reference in New Issue
Block a user