Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4fac9a8

Browse filesBrowse files
author
Charlotte Gerhaher
authored
feat: add install instructions for hnswlib and elastic doc index (#1431)
Signed-off-by: anna-charlotte <charlotte.gerhaher@jina.ai>
1 parent 0c73ad8 commit 4fac9a8
Copy full SHA for 4fac9a8

3 files changed

+22-10Lines changed: 22 additions & 10 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎docarray/index/backends/elastic.py‎

Copy file name to clipboardExpand all lines: docarray/index/backends/elastic.py
+20-9Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from collections import defaultdict
55
from dataclasses import dataclass, field
66
from typing import (
7+
TYPE_CHECKING,
78
Any,
89
Dict,
910
Generator,
@@ -21,9 +22,6 @@
2122
)
2223

2324
import numpy as np
24-
from elastic_transport import NodeConfig
25-
from elasticsearch import Elasticsearch
26-
from elasticsearch.helpers import parallel_bulk
2725
from pydantic import parse_obj_as
2826

2927
import docarray.typing
@@ -32,22 +30,35 @@
3230
from docarray.typing import AnyTensor
3331
from docarray.typing.tensor.abstract_tensor import AbstractTensor
3432
from docarray.typing.tensor.ndarray import NdArray
35-
from docarray.utils._internal.misc import is_tf_available, is_torch_available
33+
from docarray.utils._internal.misc import import_library
3634
from docarray.utils.find import _FindResult, _FindResultBatched
3735

3836
TSchema = TypeVar('TSchema', bound=BaseDoc)
3937
T = TypeVar('T', bound='ElasticDocIndex')
4038

4139
ELASTIC_PY_VEC_TYPES: List[Any] = [list, tuple, np.ndarray, AbstractTensor]
4240

43-
if is_torch_available():
44-
import torch
4541

46-
ELASTIC_PY_VEC_TYPES.append(torch.Tensor)
42+
if TYPE_CHECKING:
43+
from elastic_transport import NodeConfig
44+
from elasticsearch import Elasticsearch
45+
from elasticsearch.helpers import parallel_bulk
46+
else:
47+
elasticsearch = import_library('elasticsearch', raise_error=True)
48+
from elasticsearch import Elasticsearch
49+
from elasticsearch.helpers import parallel_bulk
50+
51+
elastic_transport = import_library('elastic_transport', raise_error=True)
52+
from elastic_transport import NodeConfig
53+
54+
torch = import_library('torch', raise_error=False)
55+
tf = import_library('tensorflow', raise_error=False)
4756

48-
if is_tf_available():
49-
import tensorflow as tf # type: ignore
5057

58+
if torch is not None:
59+
ELASTIC_PY_VEC_TYPES.append(torch.Tensor)
60+
61+
if tf is not None:
5162
from docarray.typing import TensorFlowTensor
5263

5364
ELASTIC_PY_VEC_TYPES.append(tf.Tensor)
Collapse file

‎docarray/index/backends/hnswlib.py‎

Copy file name to clipboardExpand all lines: docarray/index/backends/hnswlib.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
from docarray.typing import TensorFlowTensor
4343
else:
44-
hnswlib = import_library('hnswlib', raise_error=False)
44+
hnswlib = import_library('hnswlib', raise_error=True)
4545
torch = import_library('torch', raise_error=False)
4646
tf = import_library('tensorflow', raise_error=False)
4747
if tf is not None:
Collapse file

‎docarray/utils/_internal/misc.py‎

Copy file name to clipboardExpand all lines: docarray/utils/_internal/misc.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
'trimesh': '"docarray[mesh]"',
3333
'hnswlib': '"docarray[hnswlib]"',
3434
'elasticsearch': '"docarray[elasticsearch]"',
35+
'elastic_transport': '"docarray[elasticsearch]"',
3536
'weaviate': '"docarray[weaviate]"',
3637
'qdrant_client': '"docarray[qdrant]"',
3738
'fastapi': '"docarray[web]"',

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.