llama-stack-mirror/llama_stack/providers/utils
Ramakrishna Reddy Yekulla 03e61e3fcc
Some checks failed
Integration Auth Tests / test-matrix (oauth2_token) (push) Failing after 1s
Integration Tests / test-matrix (http, 3.12, agents) (push) Failing after 7s
Integration Tests / test-matrix (http, 3.12, post_training) (push) Failing after 9s
Integration Tests / test-matrix (http, 3.12, providers) (push) Failing after 9s
Integration Tests / test-matrix (http, 3.13, providers) (push) Failing after 5s
Integration Tests / test-matrix (http, 3.13, datasets) (push) Failing after 7s
Integration Tests / test-matrix (http, 3.13, scoring) (push) Failing after 5s
Integration Tests / test-matrix (http, 3.13, agents) (push) Failing after 7s
Integration Tests / test-matrix (library, 3.12, datasets) (push) Failing after 6s
Integration Tests / test-matrix (http, 3.12, inspect) (push) Failing after 13s
Integration Tests / test-matrix (http, 3.12, tool_runtime) (push) Failing after 12s
Integration Tests / test-matrix (http, 3.12, inference) (push) Failing after 14s
Integration Tests / test-matrix (http, 3.13, inspect) (push) Failing after 10s
Integration Tests / test-matrix (library, 3.12, inference) (push) Failing after 9s
Integration Tests / test-matrix (library, 3.12, post_training) (push) Failing after 6s
Integration Tests / test-matrix (http, 3.13, post_training) (push) Failing after 12s
Integration Tests / test-matrix (http, 3.13, vector_io) (push) Failing after 9s
Integration Tests / test-matrix (library, 3.12, vector_io) (push) Failing after 6s
Integration Tests / test-matrix (http, 3.12, vector_io) (push) Failing after 14s
Integration Tests / test-matrix (library, 3.13, datasets) (push) Failing after 7s
Integration Tests / test-matrix (http, 3.12, scoring) (push) Failing after 24s
Integration Tests / test-matrix (library, 3.12, agents) (push) Failing after 13s
Integration Tests / test-matrix (library, 3.12, scoring) (push) Failing after 6s
Integration Tests / test-matrix (library, 3.13, inference) (push) Failing after 8s
Integration Tests / test-matrix (library, 3.12, tool_runtime) (push) Failing after 7s
Integration Tests / test-matrix (library, 3.12, inspect) (push) Failing after 11s
Integration Tests / test-matrix (library, 3.13, inspect) (push) Failing after 7s
Integration Tests / test-matrix (http, 3.13, tool_runtime) (push) Failing after 22s
Integration Tests / test-matrix (library, 3.12, providers) (push) Failing after 8s
Integration Tests / test-matrix (http, 3.12, datasets) (push) Failing after 22s
Integration Tests / test-matrix (http, 3.13, inference) (push) Failing after 23s
Integration Tests / test-matrix (library, 3.13, agents) (push) Failing after 8s
Integration Tests / test-matrix (library, 3.13, providers) (push) Failing after 8s
Integration Tests / test-matrix (library, 3.13, post_training) (push) Failing after 7s
Integration Tests / test-matrix (library, 3.13, scoring) (push) Failing after 13s
Integration Tests / test-matrix (library, 3.13, vector_io) (push) Failing after 12s
Integration Tests / test-matrix (library, 3.13, tool_runtime) (push) Failing after 14s
Vector IO Integration Tests / test-matrix (3.12, inline::faiss) (push) Failing after 12s
Vector IO Integration Tests / test-matrix (3.12, inline::sqlite-vec) (push) Failing after 10s
Vector IO Integration Tests / test-matrix (3.12, remote::chromadb) (push) Failing after 6s
Vector IO Integration Tests / test-matrix (3.12, remote::pgvector) (push) Failing after 6s
Vector IO Integration Tests / test-matrix (3.13, inline::faiss) (push) Failing after 5s
Vector IO Integration Tests / test-matrix (3.13, inline::sqlite-vec) (push) Failing after 6s
Vector IO Integration Tests / test-matrix (3.13, remote::chromadb) (push) Failing after 5s
Vector IO Integration Tests / test-matrix (3.13, remote::pgvector) (push) Failing after 7s
Python Package Build Test / build (3.12) (push) Failing after 15s
Python Package Build Test / build (3.13) (push) Failing after 17s
Test External Providers / test-external-providers (venv) (push) Failing after 20s
Unit Tests / unit-tests (3.12) (push) Failing after 21s
Unit Tests / unit-tests (3.13) (push) Failing after 11s
Pre-commit / pre-commit (push) Successful in 1m12s
fix: ValueError in faiss vector database serialization (resolves #2519) (#2526)
The error message was misleading as it appeared to be an Ollama
connectivity issue, but actually occurred during faiss vector database
initialization.

## 🔍 Root Cause Analysis

The issue was in the faiss vector database serialization logic in
`llama_stack/providers/inline/vector_io/faiss/faiss.py`:

1. **Saving**: `faiss.serialize_index()` returns binary data (uint8
numpy array)
2. **Bug**: Code incorrectly used `np.savetxt()` which converts binary
to text with scientific notation (e.g., `7.300000000000000000e+01`)
3. **Loading**: `np.loadtxt(buffer, dtype=np.uint8)` failed to parse
scientific notation back to uint8
4. **Result**: Server crashed during initialization before reaching
Ollama connectivity check

##  Solution

Replaced text-based serialization with proper binary serialization:
```

**After (fixed):**
```python
# Saving - proper binary format
np.save(buffer, np_index, allow_pickle=False)  

# Loading - proper binary format
self.index = faiss.deserialize_index(np.load(buffer,
allow_pickle=False))
```

## 🧪 Testing

-  Binary serialization/deserialization works correctly
-  Backward compatible with existing functionality
-  No security concerns (allow_pickle=False maintained)
-  Resolves the specific ValueError mentioned in the issue

## 📊 Impact

This fix resolves:
- ValueError during server startup with Ollama templates

## 🔗 Related Issues

- Closes #2519 
- Affects all users of Ollama template and faiss vector_io configurations

## 📝 Files Changed

- `llama_stack/providers/inline/vector_io/faiss/faiss.py` - Fixed serialization methods in `initialize()` and `_save_index()`

---------

Signed-off-by: Ben Browning <bbrownin@redhat.com>
Co-authored-by: Ben Browning <bbrownin@redhat.com>
2025-06-27 14:34:52 -04:00
..
bedrock feat: drop python 3.10 support (#2469) 2025-06-19 12:07:14 +05:30
common chore: enable pyupgrade fixes (#1806) 2025-05-01 14:23:50 -07:00
datasetio chore(refact): move paginate_records fn outside of datasetio (#2137) 2025-05-12 10:56:14 -07:00
inference chore: standardize unsupported model error #2517 (#2518) 2025-06-27 14:26:58 -04:00
kvstore fix: ValueError in faiss vector database serialization (resolves #2519) (#2526) 2025-06-27 14:34:52 -04:00
memory chore: remove nested imports (#2515) 2025-06-26 08:01:05 +05:30
responses feat: support auth attributes in inference/responses stores (#2389) 2025-06-20 10:24:45 -07:00
scoring chore: enable pyupgrade fixes (#1806) 2025-05-01 14:23:50 -07:00
sqlstore refactor(env)!: enhanced environment variable substitution (#2490) 2025-06-26 08:20:08 +05:30
telemetry fix: fix test of root span to match what is being set (#2494) 2025-06-26 11:41:35 -04:00
tools chore: bump python supported version to 3.12 (#2475) 2025-06-24 09:22:04 +05:30
vector_io feat: Add ChunkMetadata to Chunk (#2497) 2025-06-25 15:55:23 -04:00
__init__.py API Updates (#73) 2024-09-17 19:51:35 -07:00
pagination.py chore(refact): move paginate_records fn outside of datasetio (#2137) 2025-05-12 10:56:14 -07:00
scheduler.py chore: bump python supported version to 3.12 (#2475) 2025-06-24 09:22:04 +05:30