> ## Documentation Index
> Fetch the complete documentation index at: https://docs.upsonic.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Weaviate

> Using Weaviate as a vector database provider

## Overview

Weaviate is an open-source vector database with a GraphQL API. It supports embedded, local, and cloud deployments with schema-based collections and module configurations.

**Provider Class:** `WeaviateProvider`\
**Config Class:** `WeaviateConfig`

## Install

<Note>
  Install the Weaviate optional dependency group:

  ```bash theme={null}
  uv pip install "upsonic[weaviate]"
  ```
</Note>

## Examples

```python theme={null}
from upsonic import Agent, Task, KnowledgeBase
from upsonic.embeddings import OpenAIEmbedding, OpenAIEmbeddingConfig
from upsonic.vectordb import WeaviateProvider, WeaviateConfig, ConnectionConfig, Mode, HNSWIndexConfig

# Setup embedding provider
embedding = OpenAIEmbedding(OpenAIEmbeddingConfig())

# Embedded mode
config = WeaviateConfig(
    collection_name="my_collection",
    vector_size=1536,
    connection=ConnectionConfig(mode=Mode.EMBEDDED, db_path="./weaviate_db"),
    index=HNSWIndexConfig(m=16, ef_construction=200)
)
vectordb = WeaviateProvider(config)

# Create knowledge base
kb = KnowledgeBase(
    sources="document.pdf",
    embedding_provider=embedding,
    vectordb=vectordb
)

# Use with Agent
agent = Agent("anthropic/claude-sonnet-4-5")
task = Task(
    description="Query the documents",
    context=[kb]
)
result = agent.do(task)
```

## Parameters

### Base Parameters (from BaseVectorDBConfig)

| Parameter                      | Type                                         | Description                                              | Default                | Required |
| ------------------------------ | -------------------------------------------- | -------------------------------------------------------- | ---------------------- | -------- |
| `collection_name`              | `str`                                        | Name of the collection                                   | `"default_collection"` | No       |
| `vector_size`                  | `int`                                        | Dimension of vectors                                     | -                      | **Yes**  |
| `distance_metric`              | `DistanceMetric`                             | Similarity metric (`COSINE`, `EUCLIDEAN`, `DOT_PRODUCT`) | `COSINE`               | No       |
| `recreate_if_exists`           | `bool`                                       | Recreate collection if it exists                         | `False`                | No       |
| `default_top_k`                | `int`                                        | Default number of results                                | `10`                   | No       |
| `default_similarity_threshold` | `Optional[float]`                            | Minimum similarity score (0.0-1.0)                       | `None`                 | No       |
| `dense_search_enabled`         | `bool`                                       | Enable dense vector search                               | `True`                 | No       |
| `full_text_search_enabled`     | `bool`                                       | Enable full-text search                                  | `True`                 | No       |
| `hybrid_search_enabled`        | `bool`                                       | Enable hybrid search                                     | `True`                 | No       |
| `default_hybrid_alpha`         | `float`                                      | Default alpha for hybrid search (0.0-1.0)                | `0.5`                  | No       |
| `default_fusion_method`        | `Literal['rrf', 'weighted']`                 | Default fusion method for hybrid search                  | `'weighted'`           | No       |
| `provider_name`                | `Optional[str]`                              | Provider name                                            | `None`                 | No       |
| `provider_description`         | `Optional[str]`                              | Provider description                                     | `None`                 | No       |
| `provider_id`                  | `Optional[str]`                              | Provider ID                                              | `None`                 | No       |
| `default_metadata`             | `Optional[Dict[str, Any]]`                   | Default metadata for all records                         | `None`                 | No       |
| `indexed_fields`               | `Optional[List[Union[str, Dict[str, Any]]]]` | Fields to index for filtering                            | `None`                 | No       |

### Weaviate-Specific Parameters

| Parameter               | Type                                      | Description                                                                                    | Default             | Required |
| ----------------------- | ----------------------------------------- | ---------------------------------------------------------------------------------------------- | ------------------- | -------- |
| `connection`            | `ConnectionConfig`                        | Connection configuration (mode, db\_path, etc.)                                                | -                   | **Yes**  |
| `index`                 | `Union[HNSWIndexConfig, FlatIndexConfig]` | Index type configuration (IVF not supported)                                                   | `HNSWIndexConfig()` | No       |
| `description`           | `Optional[str]`                           | Collection description                                                                         | `None`              | No       |
| `namespace`             | `Optional[str]`                           | Tenant name for multi-tenancy (auto-enables `multi_tenancy_enabled`)                           | `None`              | No       |
| `multi_tenancy_enabled` | `bool`                                    | Enable multi-tenancy for the collection                                                        | `False`             | No       |
| `properties`            | `Optional[List[Dict[str, Any]]]`          | Custom schema properties beyond standard fields                                                | `None`              | No       |
| `references`            | `Optional[List[Dict[str, Any]]]`          | Cross-references to other collections                                                          | `None`              | No       |
| `inverted_index_config` | `Optional[Dict[str, Any]]`                | Inverted index configuration for BM25 tuning (e.g., `{'bm25': {'k1': 1.2, 'b': 0.75}}`)        | `None`              | No       |
| `replication_config`    | `Optional[Dict[str, Any]]`                | Replication configuration (e.g., `{'factor': 3, 'asyncEnabled': True}`)                        | `None`              | No       |
| `sharding_config`       | `Optional[Dict[str, Any]]`                | Sharding configuration (e.g., `{'virtualPerPhysical': 128, 'desiredCount': 2}`)                | `None`              | No       |
| `generative_config`     | `Optional[Dict[str, Any]]`                | Generative AI module configuration (e.g., `{'provider': 'openai', 'model': 'gpt-4'}`)          | `None`              | No       |
| `reranker_config`       | `Optional[Dict[str, Any]]`                | Reranker module configuration (e.g., `{'provider': 'cohere', 'model': 'rerank-english-v2.0'}`) | `None`              | No       |
| `api_keys`              | `Optional[Dict[str, str]]`                | API keys for AI modules (e.g., `{'openai': 'sk-...', 'cohere': '...'}`)                        | `None`              | No       |

### ConnectionConfig Parameters

| Parameter     | Type                  | Description                                                 | Default | Required                |
| ------------- | --------------------- | ----------------------------------------------------------- | ------- | ----------------------- |
| `mode`        | `Mode`                | Connection mode (`EMBEDDED`, `LOCAL`, `CLOUD`, `IN_MEMORY`) | -       | **Yes**                 |
| `db_path`     | `Optional[str]`       | Path for embedded/local storage                             | `None`  | Required for `EMBEDDED` |
| `host`        | `Optional[str]`       | Host address                                                | `None`  | Required for `LOCAL`    |
| `port`        | `Optional[int]`       | Port number                                                 | `None`  | Required for `LOCAL`    |
| `api_key`     | `Optional[SecretStr]` | API key for cloud/local                                     | `None`  | Required for `CLOUD`    |
| `url`         | `Optional[str]`       | Full connection URL                                         | `None`  | No                      |
| `use_tls`     | `bool`                | Use TLS encryption                                          | `True`  | No                      |
| `grpc_port`   | `Optional[int]`       | gRPC port                                                   | `None`  | No                      |
| `prefer_grpc` | `bool`                | Prefer gRPC over HTTP                                       | `False` | No                      |
| `https`       | `Optional[bool]`      | Use HTTPS                                                   | `None`  | No                      |
| `prefix`      | `Optional[str]`       | URL path prefix                                             | `None`  | No                      |
| `timeout`     | `Optional[float]`     | Request timeout in seconds                                  | `None`  | No                      |
| `location`    | `Optional[str]`       | Special location string                                     | `None`  | No                      |
