Skip to content

Commit 590b23f

Browse files
author
Joan Fontanals Martinez
committed
docs: update documentation
Signed-off-by: Joan Fontanals Martinez <joan.martinez@jina.ai>
1 parent 64a07f3 commit 590b23f

File tree

9 files changed

+69
-34
lines changed

9 files changed

+69
-34
lines changed

docarray/index/backends/elastic.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ def __init__(self, db_config=None, **kwargs):
113113

114114
@property
115115
def index_name(self):
116-
default_index_name = self._schema.__name__ if self._schema is not None else None
116+
default_index_name = (
117+
self._schema.__name__.lower() if self._schema is not None else None
118+
)
117119
if default_index_name is None:
118120
raise ValueError(
119121
'A ElasticDocIndex must be typed with a Document type.'
@@ -337,7 +339,7 @@ def _index(
337339

338340
for row in data:
339341
request = {
340-
'_index': self._index_name,
342+
'_index': self.index_name,
341343
'_id': row['id'],
342344
}
343345
for col_name, col in self._column_infos.items():
@@ -353,13 +355,13 @@ def _index(
353355
warnings.warn(str(info))
354356

355357
if refresh:
356-
self._refresh(self._index_name)
358+
self._refresh(self.index_name)
357359

358360
def num_docs(self) -> int:
359361
"""
360362
Get the number of documents.
361363
"""
362-
return self._client.count(index=self._index_name)['count']
364+
return self._client.count(index=self.index_name)['count']
363365

364366
def _del_items(
365367
self,
@@ -369,7 +371,7 @@ def _del_items(
369371
requests = []
370372
for _id in doc_ids:
371373
requests.append(
372-
{'_op_type': 'delete', '_index': self._index_name, '_id': _id}
374+
{'_op_type': 'delete', '_index': self.index_name, '_id': _id}
373375
)
374376

375377
_, warning_info = self._send_requests(requests, chunk_size)
@@ -379,7 +381,7 @@ def _del_items(
379381
ids = [info['delete']['_id'] for info in warning_info]
380382
warnings.warn(f'No document with id {ids} found')
381383

382-
self._refresh(self._index_name)
384+
self._refresh(self.index_name)
383385

384386
def _get_items(self, doc_ids: Sequence[str]) -> Sequence[TSchema]:
385387
accumulated_docs = []
@@ -420,7 +422,7 @@ def execute_query(self, query: Dict[str, Any], *args, **kwargs) -> Any:
420422
f'args and kwargs not supported for `execute_query` on {type(self)}'
421423
)
422424

423-
resp = self._client.search(index=self._index_name, **query)
425+
resp = self._client.search(index=self.index_name, **query)
424426
docs, scores = self._format_response(resp)
425427

426428
return _FindResult(documents=docs, scores=parse_obj_as(NdArray, scores))
@@ -444,7 +446,7 @@ def _find_batched(
444446
) -> _FindResultBatched:
445447
request = []
446448
for query in queries:
447-
head = {'index': self._index_name}
449+
head = {'index': self.index_name}
448450
body = self._form_search_body(query, limit, search_field)
449451
request.extend([head, body])
450452

@@ -473,7 +475,7 @@ def _filter_batched(
473475
) -> List[List[Dict]]:
474476
request = []
475477
for query in filter_queries:
476-
head = {'index': self._index_name}
478+
head = {'index': self.index_name}
477479
body = {'query': query, 'size': limit}
478480
request.extend([head, body])
479481

@@ -503,7 +505,7 @@ def _text_search_batched(
503505
) -> _FindResultBatched:
504506
request = []
505507
for query in queries:
506-
head = {'index': self._index_name}
508+
head = {'index': self.index_name}
507509
body = self._form_text_search_body(query, limit, search_field)
508510
request.extend([head, body])
509511

@@ -619,20 +621,20 @@ def _refresh(self, index_name: str):
619621

620622
def _client_put_mapping(self, mappings: Dict[str, Any]):
621623
self._client.indices.put_mapping(
622-
index=self._index_name, properties=mappings['properties']
624+
index=self.index_name, properties=mappings['properties']
623625
)
624626

625627
def _client_create(self, mappings: Dict[str, Any]):
626-
self._client.indices.create(index=self._index_name, mappings=mappings)
628+
self._client.indices.create(index=self.index_name, mappings=mappings)
627629

628630
def _client_put_settings(self, settings: Dict[str, Any]):
629-
self._client.indices.put_settings(index=self._index_name, settings=settings)
631+
self._client.indices.put_settings(index=self.index_name, settings=settings)
630632

631633
def _client_mget(self, ids: Sequence[str]):
632-
return self._client.mget(index=self._index_name, ids=ids)
634+
return self._client.mget(index=self.index_name, ids=ids)
633635

634636
def _client_search(self, **kwargs):
635-
return self._client.search(index=self._index_name, **kwargs)
637+
return self._client.search(index=self.index_name, **kwargs)
636638

637639
def _client_msearch(self, request: List[Dict[str, Any]]):
638-
return self._client.msearch(index=self._index_name, searches=request)
640+
return self._client.msearch(index=self.index_name, searches=request)

docarray/index/backends/qdrant.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def __init__(self, db_config=None, **kwargs):
8888
@property
8989
def collection_name(self):
9090
default_collection_name = (
91-
self._schema.__name__ if self._schema is not None else None
91+
self._schema.__name__.lower() if self._schema is not None else None
9292
)
9393
if default_collection_name is None:
9494
raise ValueError(

docarray/index/backends/weaviate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ class QueryBuilder(BaseDocIndex.QueryBuilder):
745745
def __init__(self, document_index):
746746
self._queries = [
747747
document_index._client.query.get(
748-
document_index._db_config.index_name, document_index.properties
748+
document_index.index_name, document_index.properties
749749
)
750750
]
751751

docs/user_guide/storing/index_elastic.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ The following configs can be set in `DBConfig`:
420420
|-------------------|----------------------------------------------------------------------------------------------------------------------------------------|-------------------------|
421421
| `hosts` | Hostname of the Elasticsearch server | `http://localhost:9200` |
422422
| `es_config` | Other ES [configuration options](https://www.elastic.co/guide/en/elasticsearch/client/python-api/8.6/config.html) in a Dict and pass to `Elasticsearch` client constructor, e.g. `cloud_id`, `api_key` | None |
423-
| `index_name` | Elasticsearch index name, the name of Elasticsearch index object | None |
423+
| `index_name` | Elasticsearch index name, the name of Elasticsearch index object | None. Data will be stored in an index named after the Document type used as schema. |
424424
| `index_settings` | Other [index settings](https://www.elastic.co/guide/en/elasticsearch/reference/8.6/index-modules.html#index-modules-settings) in a Dict for creating the index | dict |
425425
| `index_mappings` | Other [index mappings](https://www.elastic.co/guide/en/elasticsearch/reference/8.6/mapping.html) in a Dict for creating the index | dict |
426426

docs/user_guide/storing/index_qdrant.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ For general usage of a Document Index, see the [general user guide](./docindex.m
2727
runtime_config = QdrantDocumentIndex.RuntimeConfig()
2828
print(runtime_config) # shows default values
2929
```
30+
31+
Note that the collection_name from the DBConfig is an Optional[str] with None as default value. This is because
32+
the QdrantDocumentIndex will take the name the Document type that you use as schema. For example, for QdrantDocumentIndex[MyDoc](...)
33+
the data will be stored in a collection name MyDoc if no specific collection_name is passed in the DBConfig.
3034

3135
```python
3236
import numpy as np

tests/index/elastic/v7/test_column_config.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,14 @@ class MyDoc(BaseDoc):
132132

133133

134134
def test_index_name():
135-
class MyDoc(BaseDoc):
136-
expected_attendees: dict = Field(col_type='integer_range')
137-
time_frame: dict = Field(col_type='date_range', format='yyyy-MM-dd')
135+
class TextDoc(BaseDoc):
136+
text: str = Field()
138137

139-
index = ElasticV7DocIndex[MyDoc]()
140-
assert index.index_name == MyDoc.__name__
138+
class StringDoc(BaseDoc):
139+
text: str = Field(col_type="string")
140+
141+
index = ElasticV7DocIndex[TextDoc]()
142+
assert index.index_name == TextDoc.__name__
143+
144+
index = ElasticV7DocIndex[StringDoc]()
145+
assert index.index_name == StringDoc.__name__

tests/index/elastic/v8/test_column_config.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,17 @@ class MyDoc(BaseDoc):
129129
}
130130
docs, _ = index.execute_query(query)
131131
assert [doc['id'] for doc in docs] == [doc[0].id, doc[1].id]
132+
133+
134+
def test_index_name():
135+
class TextDoc(BaseDoc):
136+
text: str = Field()
137+
138+
class StringDoc(BaseDoc):
139+
text: str = Field(col_type="string")
140+
141+
index = ElasticDocIndex[TextDoc]()
142+
assert index.index_name == TextDoc.__name__
143+
144+
index = ElasticDocIndex[StringDoc]()
145+
assert index.index_name == StringDoc.__name__

tests/index/qdrant/test_index_get_del.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,14 @@ class MyMultiModalDoc(BaseDoc):
236236

237237

238238
def test_collection_name():
239-
class MyDoc(BaseDoc):
240-
expected_attendees: dict = Field(col_type='integer_range')
241-
time_frame: dict = Field(col_type='date_range', format='yyyy-MM-dd')
239+
class TextDoc(BaseDoc):
240+
text: str = Field()
242241

243-
index = QdrantDocumentIndex[MyDoc]()
244-
assert index.collection_name == MyDoc.__name__
242+
class StringDoc(BaseDoc):
243+
text: str = Field(col_type="string")
244+
245+
index = QdrantDocumentIndex[TextDoc]()
246+
assert index.collection_name == TextDoc.__name__
247+
248+
index = QdrantDocumentIndex[StringDoc]()
249+
assert index.collection_name == StringDoc.__name__

tests/index/weaviate/test_column_config_weaviate.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,14 @@ class StringDoc(BaseDoc):
3737

3838

3939
def test_index_name():
40-
class MyDoc(BaseDoc):
41-
expected_attendees: dict = Field(col_type='integer_range')
42-
time_frame: dict = Field(col_type='date_range', format='yyyy-MM-dd')
40+
class TextDoc(BaseDoc):
41+
text: str = Field()
42+
43+
class StringDoc(BaseDoc):
44+
text: str = Field(col_type="string")
45+
46+
index = WeaviateDocumentIndex[TextDoc]()
47+
assert index.index_name == TextDoc.__name__
4348

44-
index = WeaviateDocumentIndex[MyDoc]()
45-
assert index.index_name == MyDoc.__name__
49+
index = WeaviateDocumentIndex[StringDoc]()
50+
assert index.index_name == StringDoc.__name__

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy