Almaatla commited on
Commit
f238fcb
·
verified ·
1 Parent(s): a0edacc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -14,6 +14,9 @@ templates = Jinja2Templates(directory=".")
14
  class EmbedRequest(BaseModel):
15
  texts: list[str]
16
 
 
 
 
17
 
18
  @app.get("/")
19
  def read_root(request: Request):
@@ -26,7 +29,7 @@ def embed_strings(request: EmbedRequest):
26
  return {"message": "Strings embedded and added to FAISS database"}
27
 
28
  @app.post("/search")
29
- def search_string(text: str, n: int = 5):
30
- embedding = model.encode([text])
31
- distances, indices = index.search(np.array(embedding), n)
32
  return {"distances": distances[0].tolist(), "indices": indices[0].tolist()}
 
14
  class EmbedRequest(BaseModel):
15
  texts: list[str]
16
 
17
+ class SearchRequest(BaseModel):
18
+ text: str
19
+ n: int = 5
20
 
21
  @app.get("/")
22
  def read_root(request: Request):
 
29
  return {"message": "Strings embedded and added to FAISS database"}
30
 
31
  @app.post("/search")
32
+ def search_string(request: SearchRequest):
33
+ embedding = model.encode([request.text])
34
+ distances, indices = index.search(np.array(embedding), request.n)
35
  return {"distances": distances[0].tolist(), "indices": indices[0].tolist()}