mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-27 17:35:07 +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
21
src/main.py
21
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):
|
||||||
# Extract Entries, Generate Embeddings
|
if t == 'notes' or t == None:
|
||||||
extracted_entries, computed_embeddings, _, _, _ = asymmetric.setup(args.input_files, args.input_filter, args.compressed_jsonl, args.embeddings, regenerate=True, verbose=args.verbose)
|
# Extract Entries, Generate Embeddings
|
||||||
|
global corpus_embeddings
|
||||||
# Now Update State
|
global entries
|
||||||
# update state variables after regeneration complete
|
entries, corpus_embeddings, _, _, _ = asymmetric.setup(args.input_files, args.input_filter, args.compressed_jsonl, args.embeddings, regenerate=True, verbose=args.verbose)
|
||||||
# minimize time the application is in inconsistent, partially updated state
|
|
||||||
global corpus_embeddings
|
|
||||||
global entries
|
|
||||||
entries = extracted_entries
|
|
||||||
corpus_embeddings = computed_embeddings
|
|
||||||
|
|
||||||
return {'status': 'ok', 'message': 'regeneration completed'}
|
return {'status': 'ok', 'message': 'regeneration completed'}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue