-p 8001:8001: Maps port 8001 on your host machine to port 8001 inside the container (where the FastAPI app runs).
-v /path/to/your/cursor_chat_history.lancedb:/data/cursor_chat_history.lancedb: This is CRUCIAL. Replace /path/to/your/cursor_chat_history.lancedb with the absolute path on your host machine to the cursor_chat_history.lancedb directory created by the extraction script. This mounts your host database into the container at /data/cursor_chat_history.lancedb, the location expected by main.py. (Use forward slashes for paths even on Windows in Docker commands, or ensure proper escaping/configuration).
-e OLLAMA_HOST="...": Sets the OLLAMA_HOST environment variable inside the container. http://host.docker.internal:11434 is common for Docker Desktop to reach the host. For Linux, you might need a different approach (e.g., host network mode, or using the host's IP accessible from the container).
The FastAPI application (your "MCP server") should now be running and accessible via http://localhost:8001.
▶️ How to Run
The overall workflow is:
Execute python cursor_history_extractor.py periodically on your host machine to create/update ./cursor_chat_history.lancedb.
Run the docker run command from the project root (where the .lancedb directory exists) to start the API server. This server will access the LanceDB database via the volume mount.
📁 Output
./cursor_chat_history.lancedb: A directory created by the extraction script containing the LanceDB vector database. Its schema includes vector (float list), text (string), source_db (string), and role (string).
A running API server inside the Docker container, accessible externally via the mapped port (default 8001), providing the defined API endpoints.
🔌 API Usage
Once the Docker container is running and the API is accessible (e.g., at http://localhost:8001), you can interact with it.
Health Check (GET /health)
Checks the server's status and its connections to Ollama and LanceDB.
Performs a vector similarity search against the LanceDB chat history.
curl -X POST http://localhost:8001/search_chat_history
-H "Content-Type: application/json"
-d '{"query_text": "How do I use Python with data analysis?", "top_k": 5}'
🔍 Direct Database Inspection
After running the cursor_history_extractor.py script, you can inspect the LanceDB database file directly using Python (outside the Docker container).
import lancedb
import ollama # Required if you want to perform searches
Connect to the DB where the extractor created it
db = lancedb.connect("./cursor_chat_history.lancedb")
try:
# Open the table
table = db.open_table("chat_history")
# Inspect the table schema and content
print("Table Schema:")
print(table.schema)
print(f"\nTotal rows: {len(table)}")
print("\nFirst 3 rows:")
print(table.limit(3).to_pandas())
# --- Example: Perform a search using this direct connection ---
# Requires Ollama running on the host where this script is executed
# try:
# query_text = "How do I use Python with data analysis?"
# ollama_model_name = "nomic-embed-text:latest"
# response = ollama.embeddings(model=ollama_model_name, prompt=query_text)
# query_vector = response["embedding"]
# search_results = table.search(query_vector).limit(5).to_pandas()
# print("\nSearch Results (Direct Access):")
# print(search_results)
# except Exception as e:
# print(f"Error during direct query or search (Is Ollama running?): {e}")
except Exception as e:
print(f"Error opening or inspecting LanceDB table: {e}")
This direct access method is useful for debugging, verifying the database content, or performing operations separate from the API.
⚠️ Troubleshooting & Notes
Ollama Connectivity: Both the extraction script and the API server depend on a running and accessible Ollama instance with the nomic-embed-text:latest model pulled. Ensure OLLAMA_HOST is correctly configured for your Docker environment.
LanceDB Mounting: The Docker container must have the LanceDB database directory mounted correctly using the -v flag in docker run. Ensure the host path is correct and that the container user has read/write permissions if needed (write permission is mainly for the extractor, read is sufficient for the API search).
Database Path: The extractor creates the DB at ./cursor_chat_history.lancedb relative to where you run the script. The Docker container expects it mounted at /data/cursor_chat_history.lancedb. These paths are important.
Empty Prompts: The extraction script adds placeholder zero vectors for empty or whitespace-only prompts to maintain vector column size consistency.
AI Model Responses: This project currently only extracts user prompts from aiService.prompts. AI model responses and other conversation details are not currently extracted or stored.
Windows Paths: Be mindful of path formats when specifying the host path for the -v flag in docker run on Windows. Use absolute paths.
✨ Future Enhancements (Potential)
Extract and store AI model responses, associating them with user prompts.
Extract and store timestamps for ordering conversations.
Add more metadata to stored documents (workspace ID, conversation ID, etc.).
Implement configuration via a .env file for both the extractor and the API server.
Add filtering options to the search API (e.g., filter by source database, date range).
C
Cursor History
markelaugust74·4 ดาว·
API service to search vectorized Cursor IDE chat history using LanceDB and Ollama