Update app.py
Browse files
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(
|
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()}
|