Skip to content

Weaviate

WeaviateVectorStore #

Bases: BasePydanticVectorStore

Weaviate vector store.

In this vector store, embeddings and docs are stored within a Weaviate collection.

During query time, the index uses Weaviate to query for the top k most similar nodes.

Parameters:

Name Type Description Default
weaviate_client Optional[Any]

Either a WeaviateClient (synchronous) or WeaviateAsyncClient (asynchronous) instance from weaviate-client package

None
index_name Optional[str]

name for Weaviate classes

None

Examples:

pip install llama-index-vector-stores-weaviate

import weaviate

resource_owner_config = weaviate.AuthClientPassword(
    username="<username>",
    password="<password>",
)
client = weaviate.Client(
    "https://llama-test-ezjahb4m.weaviate.network",
    auth_client_secret=resource_owner_config,
)

vector_store = WeaviateVectorStore(
    weaviate_client=client, index_name="LlamaIndex"
)
Source code in llama-index-integrations/vector_stores/llama-index-vector-stores-weaviate/llama_index/vector_stores/weaviate/base.py
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
class WeaviateVectorStore(BasePydanticVectorStore):
    """Weaviate vector store.

    In this vector store, embeddings and docs are stored within a
    Weaviate collection.

    During query time, the index uses Weaviate to query for the top
    k most similar nodes.

    Args:
        weaviate_client (Optional[Any]): Either a WeaviateClient (synchronous) or WeaviateAsyncClient (asynchronous)
            instance from `weaviate-client` package
        index_name (Optional[str]): name for Weaviate classes

    Examples:
        `pip install llama-index-vector-stores-weaviate`

        ```python
        import weaviate

        resource_owner_config = weaviate.AuthClientPassword(
            username="<username>",
            password="<password>",
        )
        client = weaviate.Client(
            "https://llama-test-ezjahb4m.weaviate.network",
            auth_client_secret=resource_owner_config,
        )

        vector_store = WeaviateVectorStore(
            weaviate_client=client, index_name="LlamaIndex"
        )
        ```
    """

    stores_text: bool = True

    index_name: str
    url: Optional[str]
    text_key: str
    auth_config: Dict[str, Any] = Field(default_factory=dict)
    client_kwargs: Dict[str, Any] = Field(default_factory=dict)

    _client: weaviate.WeaviateClient = PrivateAttr()
    _aclient: weaviate.WeaviateAsyncClient = PrivateAttr()

    _collection_initialized: bool = PrivateAttr()
    _is_self_created_weaviate_client: bool = (
        PrivateAttr()
    )  # States if the Weaviate client was created within this class and therefore closing it lies in our responsibility

    def __init__(
        self,
        weaviate_client: Optional[Any] = None,
        class_prefix: Optional[str] = None,
        index_name: Optional[str] = None,
        text_key: str = DEFAULT_TEXT_KEY,
        auth_config: Optional[Any] = None,
        client_kwargs: Optional[Dict[str, Any]] = None,
        url: Optional[str] = None,
        **kwargs: Any,
    ) -> None:
        """Initialize params."""
        # validate class prefix starts with a capital letter
        if class_prefix is not None:
            _logger.warning("class_prefix is deprecated, please use index_name")
            # legacy, kept for backward compatibility
            index_name = f"{class_prefix}_Node"

        index_name = index_name or f"LlamaIndex_{uuid4().hex}"
        if not index_name[0].isupper():
            raise ValueError(
                "Index name must start with a capital letter, e.g. 'LlamaIndex'"
            )

        super().__init__(
            url=url,
            index_name=index_name,
            text_key=text_key,
            auth_config=auth_config.__dict__ if auth_config else {},
            client_kwargs=client_kwargs or {},
        )
        if isinstance(weaviate_client, weaviate.WeaviateClient):
            self._client = weaviate_client
            self._aclient = None
            self._is_self_created_weaviate_client = False
        elif isinstance(weaviate_client, weaviate.WeaviateAsyncClient):
            self._client = None
            self._aclient = weaviate_client
            self._is_self_created_weaviate_client = False
        elif weaviate_client is None:
            if isinstance(auth_config, dict):
                auth_config = weaviate.auth.AuthApiKey(auth_config)

            client_kwargs = client_kwargs or {}
            self._client = weaviate.WeaviateClient(
                auth_client_secret=auth_config, **client_kwargs
            )
            self._client.connect()
            self._is_self_created_weaviate_client = True
        else:  # weaviate_client neither one of the expected types nor None
            raise ValueError(
                f"Unsupported weaviate_client of type {type(weaviate_client)}. Either provide an instance of `WeaviateClient` or `WeaviateAsyncClient` or set `weaviate_client` to None to have a sync client automatically created using the setting provided in `auth_config` and `client_kwargs`."
            )

        # create default schema if does not exist
        if self._client is not None:
            if not class_schema_exists(self._client, index_name):
                create_default_schema(self._client, index_name)
            self._collection_initialized = True
        else:
            #  need to do lazy init for async clients
            self._collection_initialized = False

    def __del__(self) -> None:
        if self._is_self_created_weaviate_client:
            self.client.close()

    @classmethod
    def class_name(cls) -> str:
        return "WeaviateVectorStore"

    @property
    def client(self) -> weaviate.WeaviateClient:
        """Get the synchronous Weaviate client, if available."""
        if self._client is None:
            raise SyncClientNotProvidedError
        return self._client

    @property
    def async_client(self) -> weaviate.WeaviateAsyncClient:
        """Get the asynchronous Weaviate client, if available."""
        if self._aclient is None:
            raise AsyncClientNotProvidedError
        return self._aclient

    def add(
        self,
        nodes: List[BaseNode],
        **add_kwargs: Any,
    ) -> List[str]:
        """Add nodes to index.

        Args:
            nodes: List[BaseNode]: list of nodes with embeddings

        """
        ids = [r.node_id for r in nodes]

        with self.client.batch.dynamic() as batch:
            for node in nodes:
                data_object = get_data_object(node=node, text_key=self.text_key)
                batch.add_object(
                    collection=self.index_name,
                    properties=data_object.properties,
                    uuid=data_object.uuid,
                    vector=data_object.vector,
                )
        return ids

    async def async_add(
        self,
        nodes: List[BaseNode],
        **add_kwargs: Any,
    ) -> List[str]:
        """Add nodes to index.

        Args:
            nodes: List[BaseNode]: list of nodes with embeddings

        Raises:
            AsyncClientNotProvidedError: If trying to use async methods without aclient
        """
        if len(nodes) > 0 and not self._collection_initialized:
            if not await aclass_schema_exists(self.async_client, self.index_name):
                await acreate_default_schema(self.async_client, self.index_name)

        ids = [r.node_id for r in nodes]

        collection = self.async_client.collections.get(self.index_name)

        response = await collection.data.insert_many(
            [get_data_object(node=node, text_key=self.text_key) for node in nodes]
        )
        return ids

    def delete(self, ref_doc_id: str, **delete_kwargs: Any) -> None:
        """
        Delete nodes using with ref_doc_id.

        Args:
            ref_doc_id (str): The doc_id of the document to delete.

        """
        collection = self.client.collections.get(self.index_name)

        where_filter = wvc.query.Filter.by_property("ref_doc_id").equal(ref_doc_id)

        if "filter" in delete_kwargs and delete_kwargs["filter"] is not None:
            where_filter = where_filter & _to_weaviate_filter(delete_kwargs["filter"])

        collection.data.delete_many(where=where_filter)

    async def adelete(self, ref_doc_id: str, **delete_kwargs: Any) -> None:
        """
        Delete nodes using with ref_doc_id.

        Args:
            ref_doc_id (str): The doc_id of the document to delete.

        Raises:
            AsyncClientNotProvidedError: If trying to use async methods without aclient
        """
        collection = self.async_client.collections.get(self.index_name)

        where_filter = wvc.query.Filter.by_property("ref_doc_id").equal(ref_doc_id)

        if "filter" in delete_kwargs and delete_kwargs["filter"] is not None:
            where_filter = where_filter & _to_weaviate_filter(delete_kwargs["filter"])

        result = await collection.data.delete_many(where=where_filter)

    def delete_index(self) -> None:
        """Delete the index associated with the client.

        Raises:
        - Exception: If the deletion fails, for some reason.
        """
        if not class_schema_exists(self.client, self.index_name):
            _logger.warning(
                f"Index '{self.index_name}' does not exist. No action taken."
            )
            return
        try:
            self.client.collections.delete(self.index_name)
            _logger.info(f"Successfully deleted index '{self.index_name}'.")
        except Exception as e:
            _logger.error(f"Failed to delete index '{self.index_name}': {e}")
            raise Exception(f"Failed to delete index '{self.index_name}': {e}")

    def delete_nodes(
        self,
        node_ids: Optional[List[str]] = None,
        filters: Optional[MetadataFilters] = None,
        **delete_kwargs: Any,
    ) -> None:
        """Deletes nodes.

        Args:
            node_ids (Optional[List[str]], optional): IDs of nodes to delete. Defaults to None.
            filters (Optional[MetadataFilters], optional): Metadata filters. Defaults to None.
        """
        if not node_ids and not filters:
            return

        collection = self.client.collections.get(self.index_name)

        if node_ids:
            filter = wvc.query.Filter.by_id().contains_any(node_ids or [])

        if filters:
            if node_ids:
                filter = filter & _to_weaviate_filter(filters)
            else:
                filter = _to_weaviate_filter(filters)

        collection.data.delete_many(where=filter, **delete_kwargs)

    async def adelete_nodes(
        self,
        node_ids: Optional[List[str]] = None,
        filters: Optional[MetadataFilters] = None,
        **delete_kwargs: Any,
    ) -> None:
        """Deletes nodes.

        Args:
            node_ids (Optional[List[str]], optional): IDs of nodes to delete. Defaults to None.
            filters (Optional[MetadataFilters], optional): Metadata filters. Defaults to None.

        Raises:
            AsyncClientNotProvidedError: If trying to use async methods without aclient
        """
        if not node_ids and not filters:
            return

        collection = self.async_client.collections.get(self.index_name)

        if node_ids:
            filter = wvc.query.Filter.by_id().contains_any(node_ids or [])

        if filters:
            if node_ids:
                filter = filter & _to_weaviate_filter(filters)
            else:
                filter = _to_weaviate_filter(filters)

        await collection.data.delete_many(where=filter, **delete_kwargs)

    def clear(self) -> None:
        """Clears index."""
        self.delete_index()

    async def aclear(self) -> None:
        """Delete the index associated with the client.

        Raises:
        - Exception: If the deletion fails, for some reason.
        - AsyncClientNotProvidedError: If trying to use async methods without aclient
        """
        if not await aclass_schema_exists(self.async_client, self.index_name):
            _logger.warning(
                f"Index '{self.index_name}' does not exist. No action taken."
            )
            return
        try:
            await self.async_client.collections.delete(self.index_name)
            _logger.info(f"Successfully deleted index '{self.index_name}'.")
        except Exception as e:
            _logger.error(f"Failed to delete index '{self.index_name}': {e}")
            raise Exception(f"Failed to delete index '{self.index_name}': {e}")

    def get_query_parameters(self, query: VectorStoreQuery, **kwargs: Any):
        filters = None

        # list of documents to constrain search
        if query.doc_ids:
            filters = wvc.query.Filter.by_property("doc_id").contains_any(query.doc_ids)

        if query.node_ids:
            filters = wvc.query.Filter.by_property("id").contains_any(query.node_ids)

        return_metatada = wvc.query.MetadataQuery(distance=True, score=True)

        vector = query.query_embedding
        alpha = 1
        if query.mode == VectorStoreQueryMode.HYBRID:
            _logger.debug(f"Using hybrid search with alpha {query.alpha}")
            if vector is not None and query.query_str:
                alpha = query.alpha or 0.5

        if query.filters is not None:
            filters = _to_weaviate_filter(query.filters)
        elif "filter" in kwargs and kwargs["filter"] is not None:
            filters = kwargs["filter"]

        limit = query.similarity_top_k
        _logger.debug(f"Using limit of {query.similarity_top_k}")

        query_parameters = {
            "query": query.query_str,
            "vector": vector,
            "alpha": alpha,
            "limit": limit,
            "filters": filters,
            "return_metadata": return_metatada,
            "include_vector": True,
        }
        query_parameters.update(kwargs)
        return query_parameters

    def parse_query_result(
        self, query_result: Any, query: VectorStoreQuery
    ) -> VectorStoreQueryResult:
        entries = query_result.objects

        similarity_key = "score"
        similarities = []
        nodes: List[BaseNode] = []
        node_ids = []

        for i, entry in enumerate(entries):
            if i < query.similarity_top_k:
                entry_as_dict = entry.__dict__
                similarities.append(get_node_similarity(entry_as_dict, similarity_key))
                nodes.append(to_node(entry_as_dict, text_key=self.text_key))
                node_ids.append(nodes[-1].node_id)
            else:
                break

        return VectorStoreQueryResult(
            nodes=nodes, ids=node_ids, similarities=similarities
        )

    def query(self, query: VectorStoreQuery, **kwargs: Any) -> VectorStoreQueryResult:
        """Query index for top k most similar nodes."""
        collection = self.client.collections.get(self.index_name)
        query_parameters = self.get_query_parameters(query, **kwargs)

        # execute query
        try:
            query_result = collection.query.hybrid(**query_parameters)
        except weaviate.exceptions.WeaviateQueryError as e:
            raise ValueError(f"Invalid query, got errors: {e.message}")

        # parse results
        return self.parse_query_result(query_result, query)

    async def aquery(
        self, query: VectorStoreQuery, **kwargs: Any
    ) -> VectorStoreQueryResult:
        """Query index for top k most similar nodes.

        Raises:
            AsyncClientNotProvidedError: If trying to use async methods without aclient
        """
        collection = self.async_client.collections.get(self.index_name)
        query_parameters = self.get_query_parameters(query, **kwargs)

        # execute query
        try:
            query_result = await collection.query.hybrid(**query_parameters)
        except weaviate.exceptions.WeaviateQueryError as e:
            raise ValueError(f"Invalid query, got errors: {e.message}")

        # parse results
        return self.parse_query_result(query_result, query)

client property #

client: WeaviateClient

Get the synchronous Weaviate client, if available.

async_client property #

async_client: WeaviateAsyncClient

Get the asynchronous Weaviate client, if available.

add #

add(nodes: List[BaseNode], **add_kwargs: Any) -> List[str]

Add nodes to index.

Parameters:

Name Type Description Default
nodes List[BaseNode]

List[BaseNode]: list of nodes with embeddings

required
Source code in llama-index-integrations/vector_stores/llama-index-vector-stores-weaviate/llama_index/vector_stores/weaviate/base.py
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
def add(
    self,
    nodes: List[BaseNode],
    **add_kwargs: Any,
) -> List[str]:
    """Add nodes to index.

    Args:
        nodes: List[BaseNode]: list of nodes with embeddings

    """
    ids = [r.node_id for r in nodes]

    with self.client.batch.dynamic() as batch:
        for node in nodes:
            data_object = get_data_object(node=node, text_key=self.text_key)
            batch.add_object(
                collection=self.index_name,
                properties=data_object.properties,
                uuid=data_object.uuid,
                vector=data_object.vector,
            )
    return ids

async_add async #

async_add(nodes: List[BaseNode], **add_kwargs: Any) -> List[str]

Add nodes to index.

Parameters:

Name Type Description Default
nodes List[BaseNode]

List[BaseNode]: list of nodes with embeddings

required

Raises:

Type Description
AsyncClientNotProvidedError

If trying to use async methods without aclient

Source code in llama-index-integrations/vector_stores/llama-index-vector-stores-weaviate/llama_index/vector_stores/weaviate/base.py
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
async def async_add(
    self,
    nodes: List[BaseNode],
    **add_kwargs: Any,
) -> List[str]:
    """Add nodes to index.

    Args:
        nodes: List[BaseNode]: list of nodes with embeddings

    Raises:
        AsyncClientNotProvidedError: If trying to use async methods without aclient
    """
    if len(nodes) > 0 and not self._collection_initialized:
        if not await aclass_schema_exists(self.async_client, self.index_name):
            await acreate_default_schema(self.async_client, self.index_name)

    ids = [r.node_id for r in nodes]

    collection = self.async_client.collections.get(self.index_name)

    response = await collection.data.insert_many(
        [get_data_object(node=node, text_key=self.text_key) for node in nodes]
    )
    return ids

delete #

delete(ref_doc_id: str, **delete_kwargs: Any) -> None

Delete nodes using with ref_doc_id.

Parameters:

Name Type Description Default
ref_doc_id str

The doc_id of the document to delete.

required
Source code in llama-index-integrations/vector_stores/llama-index-vector-stores-weaviate/llama_index/vector_stores/weaviate/base.py
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
def delete(self, ref_doc_id: str, **delete_kwargs: Any) -> None:
    """
    Delete nodes using with ref_doc_id.

    Args:
        ref_doc_id (str): The doc_id of the document to delete.

    """
    collection = self.client.collections.get(self.index_name)

    where_filter = wvc.query.Filter.by_property("ref_doc_id").equal(ref_doc_id)

    if "filter" in delete_kwargs and delete_kwargs["filter"] is not None:
        where_filter = where_filter & _to_weaviate_filter(delete_kwargs["filter"])

    collection.data.delete_many(where=where_filter)

adelete async #

adelete(ref_doc_id: str, **delete_kwargs: Any) -> None

Delete nodes using with ref_doc_id.

Parameters:

Name Type Description Default
ref_doc_id str

The doc_id of the document to delete.

required

Raises:

Type Description
AsyncClientNotProvidedError

If trying to use async methods without aclient

Source code in llama-index-integrations/vector_stores/llama-index-vector-stores-weaviate/llama_index/vector_stores/weaviate/base.py
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
async def adelete(self, ref_doc_id: str, **delete_kwargs: Any) -> None:
    """
    Delete nodes using with ref_doc_id.

    Args:
        ref_doc_id (str): The doc_id of the document to delete.

    Raises:
        AsyncClientNotProvidedError: If trying to use async methods without aclient
    """
    collection = self.async_client.collections.get(self.index_name)

    where_filter = wvc.query.Filter.by_property("ref_doc_id").equal(ref_doc_id)

    if "filter" in delete_kwargs and delete_kwargs["filter"] is not None:
        where_filter = where_filter & _to_weaviate_filter(delete_kwargs["filter"])

    result = await collection.data.delete_many(where=where_filter)

delete_index #

delete_index() -> None

Delete the index associated with the client.

Raises: - Exception: If the deletion fails, for some reason.

Source code in llama-index-integrations/vector_stores/llama-index-vector-stores-weaviate/llama_index/vector_stores/weaviate/base.py
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
def delete_index(self) -> None:
    """Delete the index associated with the client.

    Raises:
    - Exception: If the deletion fails, for some reason.
    """
    if not class_schema_exists(self.client, self.index_name):
        _logger.warning(
            f"Index '{self.index_name}' does not exist. No action taken."
        )
        return
    try:
        self.client.collections.delete(self.index_name)
        _logger.info(f"Successfully deleted index '{self.index_name}'.")
    except Exception as e:
        _logger.error(f"Failed to delete index '{self.index_name}': {e}")
        raise Exception(f"Failed to delete index '{self.index_name}': {e}")

delete_nodes #

delete_nodes(node_ids: Optional[List[str]] = None, filters: Optional[MetadataFilters] = None, **delete_kwargs: Any) -> None

Deletes nodes.

Parameters:

Name Type Description Default
node_ids Optional[List[str]]

IDs of nodes to delete. Defaults to None.

None
filters Optional[MetadataFilters]

Metadata filters. Defaults to None.

None
Source code in llama-index-integrations/vector_stores/llama-index-vector-stores-weaviate/llama_index/vector_stores/weaviate/base.py
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
def delete_nodes(
    self,
    node_ids: Optional[List[str]] = None,
    filters: Optional[MetadataFilters] = None,
    **delete_kwargs: Any,
) -> None:
    """Deletes nodes.

    Args:
        node_ids (Optional[List[str]], optional): IDs of nodes to delete. Defaults to None.
        filters (Optional[MetadataFilters], optional): Metadata filters. Defaults to None.
    """
    if not node_ids and not filters:
        return

    collection = self.client.collections.get(self.index_name)

    if node_ids:
        filter = wvc.query.Filter.by_id().contains_any(node_ids or [])

    if filters:
        if node_ids:
            filter = filter & _to_weaviate_filter(filters)
        else:
            filter = _to_weaviate_filter(filters)

    collection.data.delete_many(where=filter, **delete_kwargs)

adelete_nodes async #

adelete_nodes(node_ids: Optional[List[str]] = None, filters: Optional[MetadataFilters] = None, **delete_kwargs: Any) -> None

Deletes nodes.

Parameters:

Name Type Description Default
node_ids Optional[List[str]]

IDs of nodes to delete. Defaults to None.

None
filters Optional[MetadataFilters]

Metadata filters. Defaults to None.

None

Raises:

Type Description
AsyncClientNotProvidedError

If trying to use async methods without aclient

Source code in llama-index-integrations/vector_stores/llama-index-vector-stores-weaviate/llama_index/vector_stores/weaviate/base.py
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
async def adelete_nodes(
    self,
    node_ids: Optional[List[str]] = None,
    filters: Optional[MetadataFilters] = None,
    **delete_kwargs: Any,
) -> None:
    """Deletes nodes.

    Args:
        node_ids (Optional[List[str]], optional): IDs of nodes to delete. Defaults to None.
        filters (Optional[MetadataFilters], optional): Metadata filters. Defaults to None.

    Raises:
        AsyncClientNotProvidedError: If trying to use async methods without aclient
    """
    if not node_ids and not filters:
        return

    collection = self.async_client.collections.get(self.index_name)

    if node_ids:
        filter = wvc.query.Filter.by_id().contains_any(node_ids or [])

    if filters:
        if node_ids:
            filter = filter & _to_weaviate_filter(filters)
        else:
            filter = _to_weaviate_filter(filters)

    await collection.data.delete_many(where=filter, **delete_kwargs)

clear #

clear() -> None

Clears index.

Source code in llama-index-integrations/vector_stores/llama-index-vector-stores-weaviate/llama_index/vector_stores/weaviate/base.py
407
408
409
def clear(self) -> None:
    """Clears index."""
    self.delete_index()

aclear async #

aclear() -> None

Delete the index associated with the client.

Raises: - Exception: If the deletion fails, for some reason. - AsyncClientNotProvidedError: If trying to use async methods without aclient

Source code in llama-index-integrations/vector_stores/llama-index-vector-stores-weaviate/llama_index/vector_stores/weaviate/base.py
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
async def aclear(self) -> None:
    """Delete the index associated with the client.

    Raises:
    - Exception: If the deletion fails, for some reason.
    - AsyncClientNotProvidedError: If trying to use async methods without aclient
    """
    if not await aclass_schema_exists(self.async_client, self.index_name):
        _logger.warning(
            f"Index '{self.index_name}' does not exist. No action taken."
        )
        return
    try:
        await self.async_client.collections.delete(self.index_name)
        _logger.info(f"Successfully deleted index '{self.index_name}'.")
    except Exception as e:
        _logger.error(f"Failed to delete index '{self.index_name}': {e}")
        raise Exception(f"Failed to delete index '{self.index_name}': {e}")

query #

query(query: VectorStoreQuery, **kwargs: Any) -> VectorStoreQueryResult

Query index for top k most similar nodes.

Source code in llama-index-integrations/vector_stores/llama-index-vector-stores-weaviate/llama_index/vector_stores/weaviate/base.py
492
493
494
495
496
497
498
499
500
501
502
503
504
def query(self, query: VectorStoreQuery, **kwargs: Any) -> VectorStoreQueryResult:
    """Query index for top k most similar nodes."""
    collection = self.client.collections.get(self.index_name)
    query_parameters = self.get_query_parameters(query, **kwargs)

    # execute query
    try:
        query_result = collection.query.hybrid(**query_parameters)
    except weaviate.exceptions.WeaviateQueryError as e:
        raise ValueError(f"Invalid query, got errors: {e.message}")

    # parse results
    return self.parse_query_result(query_result, query)

aquery async #

aquery(query: VectorStoreQuery, **kwargs: Any) -> VectorStoreQueryResult

Query index for top k most similar nodes.

Raises:

Type Description
AsyncClientNotProvidedError

If trying to use async methods without aclient

Source code in llama-index-integrations/vector_stores/llama-index-vector-stores-weaviate/llama_index/vector_stores/weaviate/base.py
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
async def aquery(
    self, query: VectorStoreQuery, **kwargs: Any
) -> VectorStoreQueryResult:
    """Query index for top k most similar nodes.

    Raises:
        AsyncClientNotProvidedError: If trying to use async methods without aclient
    """
    collection = self.async_client.collections.get(self.index_name)
    query_parameters = self.get_query_parameters(query, **kwargs)

    # execute query
    try:
        query_result = await collection.query.hybrid(**query_parameters)
    except weaviate.exceptions.WeaviateQueryError as e:
        raise ValueError(f"Invalid query, got errors: {e.message}")

    # parse results
    return self.parse_query_result(query_result, query)