> ## 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.

# FAISS

> Using FAISS as a vector database provider

## Overview

FAISS (Facebook AI Similarity Search) is a library for efficient similarity search and clustering of dense vectors. It supports local file-based storage with HNSW, IVF\_FLAT, and FLAT index types, plus quantization options.

**Provider Class:** `FaissProvider`\
**Config Class:** `FaissConfig`

## Install

<Note>
  Install the FAISS optional dependency group:

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

## Examples

```python theme={null}
from upsonic import Agent, Task, KnowledgeBase
from upsonic.embeddings import OpenAIEmbedding, OpenAIEmbeddingConfig
from upsonic.vectordb import FaissProvider, FaissConfig, HNSWIndexConfig

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

# Create FAISS configuration
config = FaissConfig(
    collection_name="my_collection",
    vector_size=1536,
    db_path="./faiss_db",
    index=HNSWIndexConfig(m=16, ef_construction=200),
    normalize_vectors=True
)
vectordb = FaissProvider(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="Search 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       |

### FAISS-Specific Parameters

| Parameter           | Type                                     | Description                                                                       | Default             | Required |
| ------------------- | ---------------------------------------- | --------------------------------------------------------------------------------- | ------------------- | -------- |
| `db_path`           | `Optional[str]`                          | Path for persistent storage (required except in-memory)                           | `None`              | No       |
| `index`             | `IndexConfig`                            | Index type configuration (`HNSWIndexConfig`, `IVFIndexConfig`, `FlatIndexConfig`) | `HNSWIndexConfig()` | No       |
| `normalize_vectors` | `bool`                                   | Auto-normalize vectors for cosine similarity (must be `True` for `COSINE` metric) | `True`              | No       |
| `quantization_type` | `Optional[Literal['scalar', 'product']]` | Quantization method for compression                                               | `None`              | No       |
| `quantization_bits` | `int`                                    | Bits for quantization                                                             | `8`                 | No       |
