| 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 | |
| def greet_json(): | |
| return {"Hello": "World!"} | |
| def embed_string(text: str): | |
| embedding = model.encode([text]) | |
| index.add(np.array(embedding)) | |
| return {"message": "String embedded and added to FAISS database"} | |