mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-30 10:53:02 +01:00
Pass type of item via regenerate API. Default type query param to None
This commit is contained in:
parent
ff7207a6bd
commit
252266b62a
1 changed files with 8 additions and 13 deletions
15
src/main.py
15
src/main.py
|
@ -18,7 +18,7 @@ app = FastAPI()
|
||||||
|
|
||||||
|
|
||||||
@app.get('/search')
|
@app.get('/search')
|
||||||
def search(q: str, n: Optional[int] = 5, t: Optional[str] = 'notes'):
|
def search(q: str, n: Optional[int] = 5, t: Optional[str] = None):
|
||||||
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')
|
||||||
return {}
|
return {}
|
||||||
|
@ -26,7 +26,7 @@ def search(q: str, n: Optional[int] = 5, t: Optional[str] = 'notes'):
|
||||||
user_query = q
|
user_query = q
|
||||||
results_count = n
|
results_count = n
|
||||||
|
|
||||||
if t == 'notes':
|
if t == 'notes' or t == None:
|
||||||
# query notes
|
# query notes
|
||||||
hits = asymmetric.query_notes(
|
hits = asymmetric.query_notes(
|
||||||
user_query,
|
user_query,
|
||||||
|
@ -44,17 +44,12 @@ def search(q: str, n: Optional[int] = 5, t: Optional[str] = 'notes'):
|
||||||
|
|
||||||
|
|
||||||
@app.get('/regenerate')
|
@app.get('/regenerate')
|
||||||
def regenerate():
|
def regenerate(t: Optional[str] = None):
|
||||||
|
if t == 'notes' or t == None:
|
||||||
# Extract Entries, Generate Embeddings
|
# Extract Entries, Generate Embeddings
|
||||||
extracted_entries, computed_embeddings, _, _, _ = asymmetric.setup(args.input_files, args.input_filter, args.compressed_jsonl, args.embeddings, regenerate=True, verbose=args.verbose)
|
|
||||||
|
|
||||||
# Now Update State
|
|
||||||
# update state variables after regeneration complete
|
|
||||||
# minimize time the application is in inconsistent, partially updated state
|
|
||||||
global corpus_embeddings
|
global corpus_embeddings
|
||||||
global entries
|
global entries
|
||||||
entries = extracted_entries
|
entries, corpus_embeddings, _, _, _ = asymmetric.setup(args.input_files, args.input_filter, args.compressed_jsonl, args.embeddings, regenerate=True, verbose=args.verbose)
|
||||||
corpus_embeddings = computed_embeddings
|
|
||||||
|
|
||||||
return {'status': 'ok', 'message': 'regeneration completed'}
|
return {'status': 'ok', 'message': 'regeneration completed'}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue