Usage
Installation
To use FAISS in your mem0 project, you need to install the appropriate FAISS package for your environment:Config
Here are the parameters available for configuring FAISS:Parameter | Description | Default Value |
---|---|---|
collection_name | The name of the collection | mem0 |
path | Path to store FAISS index and metadata | /tmp/faiss/<collection_name> |
distance_strategy | Distance metric strategy to use (options: ‘euclidean’, ‘inner_product’, ‘cosine’) | euclidean |
normalize_L2 | Whether to normalize L2 vectors (only applicable for euclidean distance) | False |
Performance Considerations
FAISS offers several advantages for vector search:- Efficiency: FAISS is optimized for memory usage and speed, making it suitable for large-scale applications.
- Offline Support: FAISS works entirely locally, with no need for external servers or API calls.
- Storage Options: Vectors can be stored in-memory for maximum speed or persisted to disk.
- Multiple Index Types: FAISS supports different index types optimized for various use cases (though mem0 currently uses the basic flat index).
Distance Strategies
FAISS in mem0 supports three distance strategies:- euclidean: L2 distance, suitable for most embedding models
- inner_product: Dot product similarity, useful for some specialized embeddings
- cosine: Cosine similarity, best for comparing semantic similarity regardless of vector magnitude
cosine
or inner_product
with normalized vectors, you may want to set normalize_L2=True
for better results.