A semantic search API using FastAPI, FAISS, and sentence-transformers to serve related blog posts based on content similarity.
- 🔍 Uses
sentence-transformersto generate embeddings - ⚡ Fast vector search with FAISS
- 🔗 Fetches real posts from WordPress
- 🔐 Secured with API Key
- 🌐 CORS support for frontend integration
- Python 3.8+
- pip
git clone https://github.com/your-username/fastapi-ai-related.git
cd fastapi-ai-related
pip install -r requirements.txtuvicorn main:app --reloadThen access:
http://localhost:8000/related-posts?post_id=1with headerX-Api-Key: your-secret-tokenhttp://localhost:8000/health
docker build -t fastapi-ai-related .
docker run -d -p 8000:8000 fastapi-ai-relatedEdit app/config.py:
WP_API_URL = "https://yourdomain.com/wp-json/wp/v2/posts?...&_fields=id,title.rendered,content.rendered"
API_KEY = "your-secret-token".
├── main.py
├── requirements.txt
└── app/
├── config.py
├── models.py
├── faiss_index.py
├── related.py
└── __init__.py
- Schedule CRON to re-index new posts
- Add admin reload route
- Connect to Redis for persistent cache