File size: 522 Bytes
00a8910
3ab82e8
 
 
3eec3b2
00a8910
3ab82e8
 
3eec3b2
00a8910
 
 
3ab82e8
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from fastapi import FastAPI
from sentence_transformers import SentenceTransformer
import faiss
import numpy as np

app = FastAPI()
model = SentenceTransformer('paraphrase-MiniLM-L6-v2')
index = faiss.IndexFlatL2(384)  # 384 is the dimensionality of the MiniLM model

@app.get("/")
def greet_json():
    return {"Hello": "World!"}

@app.post("/embed")
def embed_string(text: str):
    embedding = model.encode([text])
    index.add(np.array(embedding))
    return {"message": "String embedded and added to FAISS database"}