mirror of
https://github.com/khoj-ai/khoj.git
synced 2025-02-17 08:04:21 +00:00
Cache queries in /search controller using LRU cache
- Most concretely right now, it eliminates the re-rank latency hit on re-rank triggered on user hitting enter after re-rank is already done on user idle in the emacs interface - Improves search latency of (incremental) search
This commit is contained in:
parent
38df727ef4
commit
555c1088cc
1 changed files with 2 additions and 0 deletions
|
@ -3,6 +3,7 @@ import sys, json, yaml
|
||||||
import time
|
import time
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from functools import lru_cache
|
||||||
|
|
||||||
# External Packages
|
# External Packages
|
||||||
import uvicorn
|
import uvicorn
|
||||||
|
@ -62,6 +63,7 @@ async def config_data(updated_config: FullConfig):
|
||||||
return config
|
return config
|
||||||
|
|
||||||
@app.get('/search')
|
@app.get('/search')
|
||||||
|
@lru_cache(maxsize=100)
|
||||||
def search(q: str, n: Optional[int] = 5, t: Optional[SearchType] = None, r: Optional[bool] = False):
|
def search(q: str, n: Optional[int] = 5, t: Optional[SearchType] = None, r: Optional[bool] = False):
|
||||||
if q is None or q == '':
|
if q is None or q == '':
|
||||||
print(f'No query param (q) passed in API call to initiate search')
|
print(f'No query param (q) passed in API call to initiate search')
|
||||||
|
|
Loading…
Add table
Reference in a new issue