mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-23 23:48:56 +01:00
Set max cos distance to 0.18. Test search API query with max distance
This commit is contained in:
parent
18dbad5edb
commit
922983bd53
2 changed files with 22 additions and 5 deletions
|
@ -376,7 +376,7 @@ async def search(
|
|||
# initialize variables
|
||||
user_query = q.strip()
|
||||
results_count = n or 5
|
||||
max_distance = max_distance if max_distance is not None else math.inf
|
||||
max_distance = max_distance or math.inf
|
||||
search_futures: List[concurrent.futures.Future] = []
|
||||
|
||||
# return cached results, if available
|
||||
|
@ -581,7 +581,7 @@ async def chat(
|
|||
request: Request,
|
||||
q: str,
|
||||
n: Optional[int] = 5,
|
||||
d: Optional[float] = 0.15,
|
||||
d: Optional[float] = 0.18,
|
||||
client: Optional[str] = None,
|
||||
stream: Optional[bool] = False,
|
||||
user_agent: Optional[str] = Header(None),
|
||||
|
|
|
@ -255,13 +255,30 @@ def test_notes_search(client, search_config: SearchConfig, sample_org_data, defa
|
|||
user_query = quote("How to git install application?")
|
||||
|
||||
# Act
|
||||
response = client.get(f"/api/search?q={user_query}&n=1&t=org&r=true", headers=headers)
|
||||
response = client.get(f"/api/search?q={user_query}&n=1&t=org&r=true&max_distance=0.18", headers=headers)
|
||||
|
||||
# Assert
|
||||
assert response.status_code == 200
|
||||
# assert actual_data contains "Khoj via Emacs" entry
|
||||
|
||||
assert len(response.json()) == 1, "Expected only 1 result"
|
||||
search_result = response.json()[0]["entry"]
|
||||
assert "git clone https://github.com/khoj-ai/khoj" in search_result
|
||||
assert "git clone https://github.com/khoj-ai/khoj" in search_result, "Expected 'git clone' in search result"
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------
|
||||
@pytest.mark.django_db(transaction=True)
|
||||
def test_notes_search_no_results(client, search_config: SearchConfig, sample_org_data, default_user: KhojUser):
|
||||
# Arrange
|
||||
headers = {"Authorization": "Bearer kk-secret"}
|
||||
text_search.setup(OrgToEntries, sample_org_data, regenerate=False, user=default_user)
|
||||
user_query = quote("How to find my goat?")
|
||||
|
||||
# Act
|
||||
response = client.get(f"/api/search?q={user_query}&n=1&t=org&r=true&max_distance=0.18", headers=headers)
|
||||
|
||||
# Assert
|
||||
assert response.status_code == 200
|
||||
assert response.json() == [], "Expected no results"
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in a new issue