This project uses AI (via Sentence Transformers) and a vector database (Qdrant) to retrieve the most relevant database tables based on a user's natural language input.
To build a system that dynamically analyzes natural language queries and returns the most relevant subset of database tables using semantic similarity.
- Backend: FastAPI (Python)
- AI Model: Sentence Transformers (all-MiniLM-L6-v2)
- Vector Database: Qdrant
- Frontend: React.js (with plain CSS)
- Containerization: Docker & Docker Compose
- Data Format: JSON schema
- Accepts a natural language description from the user
- Converts both the schema and user query to vector embeddings
- Uses Qdrant to store and retrieve table embeddings based on similarity
- Returns relevant table names and columns in JSON format
- Frontend UI built using React for easy interaction
project-root/
├── backend/
│ ├── app.py
│ ├── schema.json
│ ├── requirements.txt
├── frontend/
│ ├── public/
│ ├── src/
│ │ └── App.js
│ ├── package.json
│ ├── Dockerfile
├── docker-compose.yml
├── README.mdgit clone https://github.com/your-username/ai-table-retriever.git
cd ai-table-retrieverMake sure Docker Desktop is running and Linux containers are enabled.
docker-compose build
docker-compose uphttp://localhost:8000
Frontend (optional) will be available at:
http://localhost:3000
POST to http://localhost:8000/retrieve-tables/ with:
{
"description": "I want to see customer names and their purchases"
}{
"tables": [
{
"table_name": "customers",
"columns": ["customer_id", "name", "age", "location"]
},
{
"table_name": "purchases",
"columns": ["purchase_id", "customer_id", "product", "amount"]
}
]
}[
{
"table_name": "customers",
"columns": ["customer_id", "name", "age", "location"]
},
{
"table_name": "purchases",
"columns": ["purchase_id", "customer_id", "product", "amount"]
},
{
"table_name": "products",
"columns": ["product_id", "product_name", "category"]
}
]Inside backend/requirements.txt:
fastapi
uvicorn
sentence-transformers
qdrant-clientall-MiniLM-L6-v2by Sentence Transformers (open-source, no API key needed)
- Make sure Docker is running
- Ensure
schema.jsonis located inside the backend folder - If Qdrant is not connecting, check port 6333 is open
- Use
docker logs backendto debug FastAPI container
This project is open-source and free to use for educational and demo purposes.