Prerequisites

1

Import GitHub Project

We’ll start by creating a new Relace Repo using GitHub as a source.
import requests

url = "https://api.relace.run/v1/repo"
headers = {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json"
}

data = {
    "source": {
        "type": "git",
        "url": "https://github.com/username/new-repository",
        "branch": "main"
    }
}

response = requests.post(url, headers=headers, json=data)

repo = response.json()
repo_id = repo["repo_id"]

print(f"Repository created with ID: {repo_id}")
Behind the scenes, we clone your repo and kick of an asychronous job to intelligently chunk and index the codebase with our code embeddings model.This process is usually fast, but for very large repositories (i.e. 100+ MB), it can take upwards of 5 minutes.
2

Perform Semantic Search

You can now use the retrieve endpoint to score files based on relevance to a query in natural language!
import requests

url = f"https://api.relace.run/v1/repo/{repo_id}/retrieve"
headers = {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json"
}
data = {
    "query": "Add a user profile component with avatar and edit functionality",
}

response = requests.post(url, headers=headers, json=data)
results = response.json()["results"]
The response will be a list of objects that provide a relevance score for each file.
[
  {
    "filename": "src/components/UserProfile.tsx",
    "score": 0.9598
  },
  {
    "filename": "src/types/user.ts",
    "score": 0.0321
  },
  {
    "filename": "src/components/Header.tsx",
    "score": 0.0014
  }
]
For more details, see our API reference.