Update app.py
Browse files
app.py
CHANGED
@@ -15,13 +15,13 @@ def read_root(request: Request):
|
|
15 |
return templates.TemplateResponse("index.html", {"request": request})
|
16 |
|
17 |
@app.post("/embed")
|
18 |
-
def embed_string(
|
19 |
-
embedding = model.encode([
|
20 |
index.add(np.array(embedding))
|
21 |
return {"message": "String embedded and added to FAISS database"}
|
22 |
|
23 |
@app.post("/search")
|
24 |
-
def search_string(
|
25 |
embedding = model.encode([text])
|
26 |
distances, indices = index.search(np.array(embedding), n)
|
27 |
return {"distances": distances[0].tolist(), "indices": indices[0].tolist()}
|
|
|
15 |
return templates.TemplateResponse("index.html", {"request": request})
|
16 |
|
17 |
@app.post("/embed")
|
18 |
+
def embed_string(text: str):
|
19 |
+
embedding = model.encode([text])
|
20 |
index.add(np.array(embedding))
|
21 |
return {"message": "String embedded and added to FAISS database"}
|
22 |
|
23 |
@app.post("/search")
|
24 |
+
def search_string(text: str, n: int = 5):
|
25 |
embedding = model.encode([text])
|
26 |
distances, indices = index.search(np.array(embedding), n)
|
27 |
return {"distances": distances[0].tolist(), "indices": indices[0].tolist()}
|