feat: Add FAISS search tool

- Implement FAISSSearchTool for vector similarity search
- Add comprehensive unit tests
- Update documentation with usage examples
- Add FAISS dependency

Closes #2118

Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
Devin AI
2025-02-13 08:21:05 +00:00
parent d3b398ed52
commit ecd16486c1
5 changed files with 169 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
import pytest
import numpy as np
from crewai.tools import FAISSSearchTool
def test_faiss_search_tool_initialization():
tool = FAISSSearchTool()
assert tool.name == "FAISS Search Tool"
assert tool.dimension == 384
def test_faiss_search_with_texts():
tool = FAISSSearchTool()
texts = [
"The quick brown fox",
"jumps over the lazy dog",
"A completely different text"
]
tool.add_texts(texts)
results = tool.run(
query="quick fox",
k=2,
score_threshold=0.5
)
assert len(results) > 0
assert isinstance(results[0]["text"], str)
assert isinstance(results[0]["score"], float)
def test_faiss_search_threshold_filtering():
tool = FAISSSearchTool()
texts = ["Text A", "Text B", "Text C"]
tool.add_texts(texts)
results = tool.run(
query="Something completely different",
score_threshold=0.99 # High threshold
)
assert len(results) == 0 # No results above threshold
def test_invalid_index_type():
with pytest.raises(ValueError):
FAISSSearchTool(index_type="INVALID")