Retrieve only relevant files from your codebase for a user request
Prepare Your Query and Codebase
user_query = "Add a user profile component with avatar and edit functionality" codebase_files = [ {"filename": "src/components/UserProfile.tsx", "content": "..."}, {"filename": "src/types/user.ts", "content": "..."}, {"filename": "src/components/Header.tsx", "content": "..."}, # ... more files ]
Call the Code Reranker API
import requests url = "https://ranker.endpoint.relace.run/v2/code/rank" api_key = "[YOUR_API_KEY]" headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json" } data = { "query": user_query, "codebase": codebase_files, "token_limit": 150000, # Set to your model's context limit with buffer room for system prompt } response = requests.post(url, headers=headers, json=data) ranked_files = response.json()
Parse Ranked Results from Response
[ { "filename": "src/components/UserProfile.tsx", "score": 0.9598 }, { "filename": "src/types/user.ts", "score": 0.0321 }, { "filename": "src/components/Header.tsx", "score": 0.0014 } ]