-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add test for vector search functionality
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import base64 | ||
import logging | ||
from unittest.mock import MagicMock, patch | ||
|
||
|
||
import pytest | ||
from fastapi.testclient import TestClient | ||
|
||
from API.database import Database | ||
from API.route import router | ||
from API.utils import init_logging_config | ||
|
||
init_logging_config() | ||
|
||
def test_vector_search(): | ||
mock_result = [ | ||
{ | ||
"Name": "Test1", | ||
"Image": "encoded_string1", | ||
"score": 0.8 | ||
}, | ||
{ | ||
"Name": "Test2", | ||
"Image": "encoded_string2", | ||
"score": 0.7 | ||
} | ||
] | ||
|
||
mock_vector_search = MagicMock(return_value=mock_result) | ||
|
||
with patch("API.database.Database.vector_search", mock_vector_search): | ||
embedding = [0.1, 0.2, 0.3] | ||
result = Database.vector_search("collection_name", embedding) | ||
|
||
assert result == mock_result | ||
mock_vector_search.assert_called_once_with("collection_name", embedding) |