mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-27 17:35:07 +01:00
Remove usage of the closure to search_notes as it's not required
This commit is contained in:
parent
649e5d1327
commit
adbf157deb
1 changed files with 7 additions and 17 deletions
24
main.py
24
main.py
|
@ -7,19 +7,6 @@ import uvicorn
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
def create_search_notes(corpus_embeddings, entries, bi_encoder, cross_encoder, top_k):
|
|
||||||
"Closure to create search_notes method from initialized model, entries and embeddings"
|
|
||||||
def search_notes(query):
|
|
||||||
return asymmetric.query_notes(
|
|
||||||
query,
|
|
||||||
corpus_embeddings,
|
|
||||||
entries,
|
|
||||||
bi_encoder,
|
|
||||||
cross_encoder,
|
|
||||||
top_k)
|
|
||||||
|
|
||||||
return search_notes
|
|
||||||
|
|
||||||
|
|
||||||
@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] = 'notes'):
|
||||||
|
@ -32,7 +19,13 @@ def search(q: str, n: Optional[int] = 5, t: Optional[str] = 'notes'):
|
||||||
|
|
||||||
if t == 'notes':
|
if t == 'notes':
|
||||||
# query notes
|
# query notes
|
||||||
hits = search_notes(user_query)
|
hits = asymmetric.query_notes(
|
||||||
|
q,
|
||||||
|
corpus_embeddings,
|
||||||
|
entries,
|
||||||
|
bi_encoder,
|
||||||
|
cross_encoder,
|
||||||
|
top_k)
|
||||||
|
|
||||||
# collate and return results
|
# collate and return results
|
||||||
return asymmetric.collate_results(hits, entries, results_count)
|
return asymmetric.collate_results(hits, entries, results_count)
|
||||||
|
@ -58,8 +51,5 @@ if __name__ == '__main__':
|
||||||
# Compute or Load Embeddings
|
# Compute or Load Embeddings
|
||||||
corpus_embeddings = asymmetric.compute_embeddings(entries, bi_encoder, args.embeddings, args.verbose)
|
corpus_embeddings = asymmetric.compute_embeddings(entries, bi_encoder, args.embeddings, args.verbose)
|
||||||
|
|
||||||
# Generate search_notes method from initialized model, entries and embeddings
|
|
||||||
search_notes = create_search_notes(corpus_embeddings, entries, bi_encoder, cross_encoder, top_k)
|
|
||||||
|
|
||||||
# Start Application Server
|
# Start Application Server
|
||||||
uvicorn.run(app)
|
uvicorn.run(app)
|
||||||
|
|
Loading…
Reference in a new issue