A system that learns coding patterns from a Git repository and provides intelligent code recommendations.
- Clone and analyze Git repositories
- Extract code patterns and style
- Generate context-aware code suggestions
- Support for multiple programming languages
- Vector-based semantic search
- Command-line interface for easy use
- Clone this repository
- Install the package in development mode:
pip install -e .
pip install code-recommenderThe easiest way to use the code recommender is through the command line.
To analyze a Git repository and create a search index:
code-recommender index https://github.com/username/repo.gitOptions:
--local-path: Specify a local directory to clone to (default: temp directory)--update: Update the repository if it already exists--no-cleanup: Keep the cloned repository after indexing--verbose: Show detailed output
Search for code suggestions based on a query:
code-recommender search "function to sort a list" --repo-url https://github.com/username/repo.gitOptions:
--repo-url: URL of the Git repository to search in--local-path: Path to a local repository-n, --num-results: Number of results to return (default: 5)--language: Filter results by programming language-i, --interactive: Start an interactive search session--verbose: Show detailed output
Generate code based on a natural language description:
code-recommender generate "a function to calculate factorial in Python" --repo-url https://github.com/username/repo.gitOptions:
--max-length: Maximum length of generated code (default: 200)--temperature: Controls randomness (0.0-1.0, lower is more deterministic, default: 0.7)--top-p: Nucleus sampling parameter (0.0-1.0, default: 0.95)--num-sequences: Number of code samples to generate (default: 1)--no-context: Disable using the indexed codebase for context--repo-url: URL of the Git repository to use for context--local-path: Path to a local repository to use for context--verbose: Show detailed output
For a continuous search experience with multiple queries in one session:
# Start interactive mode
code-recommender search --interactive --persist-dir ./flask_demo
# Then type queries interactively:
# Search query: route decorator
# Search query: error handler
# Search query: exitFeatures:
- 🔍 Continuous searching without restarting
- ⚡ Fast queries (database loaded once)
- 💡 Built-in help with
helpcommand - 🎯 Filter by language:
--language python - 📊 Limit results:
-n 3
See INTERACTIVE_MODE_GUIDE.md for detailed usage and examples.
You can also use the code recommender as a Python library:
from code_recommender import CodeRecommender
# Initialize with a Git repository URL
recommender = CodeRecommender()
# Index a repository
recommender.index_repository("https://github.com/username/repo.git")
# Get code suggestions
suggestions = recommender.get_suggestions("function to sort a list", n_results=5)
# Print the suggestions
for i, suggestion in enumerate(suggestions, 1):
print(f"Suggestion {i}:")
print(f"File: {suggestion['metadata']['file_path']}")
print(f"Function: {suggestion['metadata']['function_name']}")
print(suggestion['code'])
print("-" * 80)The code generation feature uses the bigcode/starcoder model by default, which is a state-of-the-art code generation model. The first time you use the generation feature, the model will be downloaded (about 30GB).
When you provide a repository URL or local path, the code generator will:
- Index the repository
- Find relevant code snippets based on your prompt
- Use those snippets as context for better code generation
This helps the model generate code that matches the style and patterns of the existing codebase.
# Generate code using a specific repository for context
code-recommender generate \
"a function to parse JSON configuration" \
--repo-url https://github.com/username/config-parser.git \
--max-length 300See tests/README.md for detailed information about each test.
Create a .env file in your project root to configure the application:
# Copy the example file
cp .env.example .env
# Edit with your values
nano .envExample .env file:
# Required for Claude-based generation
ANTHROPIC_API_KEY=your_api_key_here
# Optional settings
CHROMA_DB_PATH=./chroma_db
EMBEDDING_MODEL=jinaai/jina-code-embeddings-0.5b
GENERATION_MODEL=claude-sonnet-4-20250514
TOKENIZERS_PARALLELISM=false
LOG_LEVEL=INFOSee ENV_SETUP.md for detailed configuration instructions.