Cursor Rules Template for FastAPI Milvus Vector Embedding Search
Cursor Rules Template for a FastAPI service using Milvus vector embedding search. Paste this .cursorrules block to bootstrap production-grade vector search API development.
Target User
Backend developers building a FastAPI service with Milvus vector embedding search
Use Cases
- vector similarity API
- semantic search over embeddings
- document retrieval with embeddings
- search across large corpora with vector embeddings
Markdown Template
Cursor Rules Template for FastAPI Milvus Vector Embedding Search
Framework Role & Context:
- Task: Assist developers in implementing a FastAPI plus Milvus vector embedding search microservice
- Scope: API layer, vector indexing, similarity search, and result ranking using Milvus
Code Style and Style Guides:
- Language: Python 3.11
- Style: PEP8 and Black
- Typing: type hints and pydantic models
Architecture & Directory Rules:
- Project layout: app, app/api, app/core, app/models, app/vector, tests
- Milvus usage: separate vector_service module, MILVUS_CLIENT with connection config
Authentication & Security Rules:
- Auth: OAuth2 with JWT for user endpoints, API keys for internal services
- Transport: TLS in production, certificate pinning where feasible
Database and ORM Patterns:
- Milvus for vectors; use Milvus SDK for insert and search
- Use SQLAlchemy for metadata and relationships; avoid mixing vector data in RDBMS
Testing & Linting Workflows:
- Tests: pytest with httpx for API tests, fixtures for DB and Milvus mocks
- Lint: Ruff, Black, isort; pre-commit hooks
Prohibited Actions and Anti-patterns for the AI:
- Do not perform direct file I/O in request handlers
- Do not bypass Milvus collection creation at deploy
- Do not embed secrets or keys in code
- Do not rely on in-memory only storage for embeddingsOverview
The Cursor rules configuration for FastAPI with Milvus vector embedding search provides a ready-to-paste .cursorrules block to guide Cursor AI in building a robust API that indexes, searches, and returns vector-based results from Milvus.
Direct answer: This template yields a FastAPI based service using Milvus for vector search, with clear architecture, security, testing, and deployment rules.
When to Use These Cursor Rules
- When building a FastAPI API that performs vector similarity search using Milvus
- When you want standard patterns for architecture, security, and testing
- When you require a project structure that supports Milvus collections and models
- When you want Cursor AI to generate safe, production-ready code with constraints
Copyable .cursorrules Configuration
Framework Role & Context:
- Task: Assist developers in implementing a FastAPI plus Milvus vector embedding search microservice
- Scope: API layer, vector indexing, similarity search, and result ranking using Milvus
Code Style and Style Guides:
- Language: Python 3.11
- Style: PEP8 and Black
- Typing: type hints and pydantic models
Architecture & Directory Rules:
- Project layout: app, app/api, app/core, app/models, app/vector, tests
- Milvus usage: separate vector_service module, MILVUS_CLIENT with connection config
Authentication & Security Rules:
- Auth: OAuth2 with JWT for user endpoints, API keys for internal services
- Transport: TLS in production, certificate pinning where feasible
Database and ORM Patterns:
- Milvus for vectors; use Milvus SDK for insert and search
- Use SQLAlchemy for metadata and relationships; avoid mixing vector data in RDBMS
Testing & Linting Workflows:
- Tests: pytest with httpx for API tests, fixtures for DB and Milvus mocks
- Lint: Ruff, Black, isort; pre-commit hooks
Prohibited Actions and Anti-patterns for the AI:
- Do not perform direct file I/O in request handlers
- Do not bypass Milvus collection creation at deploy
- Do not embed secrets or keys in code
- Do not rely on in-memory only storage for embeddings
Recommended Project Structure
project/
app/
main.py
api/
v1/
endpoints/
dependencies/
schemas/
core/
config.py
security.py
models/
services/
vector/
milvus_client.py
tests/
requirements.txt
.env
Core Engineering Principles
- Prefer explicit typing and Pydantic models for input validation
- Isolate Milvus interactions behind a vector service layer
- Keep API handlers thin and delegate to services
- Treat embedding search as a separate concern from data persistence
- Automate testing and linting in CI
- Guard against stale indices and schema drift
Code Construction Rules
- Define Milvus connections in config and never inlined in code paths
- Index creation should be idempotent and verified at startup
- Use parameterized queries and proper vector search parameters
- Validate all input lengths and embedding shapes
- Return deterministic scores with stable ranking functions
- Keep API schemas in pydantic models and reuse them across endpoints
Security and Production Rules
- Enable TLS, rotate keys, and store secrets in a vault
- Use OAuth2 with JWT for user-facing endpoints
- Limit request size and rate limit endpoints to prevent abuse
- Sanitize inputs and avoid leaking stack traces in errors
- Audit Milvus operations and monitor search latency
Testing Checklist
- Unit test utilities for vector indexing and distance calculations
- Integration tests for FastAPI endpoints and Milvus interactions
- End-to-end tests for embedding ingestion and retrieval
- Static type checks and linting in CI
Common Mistakes to Avoid
- Assuming Milvus latency is constant across queries
- Hardcoding Milvus connection details in code
- Overfetching embeddings or returning large payloads
- Skipping input validation and error handling
FAQ
What is this Cursor Rules Template for FastAPI Milvus?
It provides a copyable .cursorrules block and stack-specific guidance to implement a FastAPI service that uses Milvus for vector embedding search, including architecture, security, testing, and deployment rules.
What stack does this template cover?
Python with FastAPI, Milvus vector database, Milvus SDK for vector operations, and Cursor AI rules for production-ready vector search APIs.
How do I paste the .cursorrules block into my project?
Copy the code block from the Copyable section and place it at the root as .cursorrules, then align your app structure with the recommended layout.
Does this template enforce security?
Yes. It includes OAuth2 with JWT for endpoints, TLS in production, secrets management, input validation, and rate limiting to reduce abuse and data leakage.
What should I test first when adopting this template?
Start with unit tests for vector utilities, then integration tests for API endpoints, and finally end-to-end tests for embedding ingestion and retrieval flows to verify Milvus interactions and response structure.