Codegen provides semantic code search capabilities using embeddings. This allows you to search codebases using natural language queries and find semantically related code, even when the exact terms aren’t present.
Here’s how to create and use a semantic code search index:
Copy
Ask AI
# Parse a codebasecodebase = Codebase.from_repo('fastapi/fastapi', language='python')# Create indexindex = FileIndex(codebase)index.create() # computes per-file embeddings# Save index to .pklindex.save('index.pkl')# Load index into memoryindex.load('index.pkl')# Update index after changescodebase.files[0].edit('# 🌈 Replacing File Content 🌈')codebase.commit()index.update() # re-computes 1 embedding