-
Notifications
You must be signed in to change notification settings - Fork 72
[feat]: add codegraph support by FalkorDB for repo indexing #138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4aef289
feat: add FalkorDB and codegraph services to docker-compose
smokeyScraper eeea9d3
[update]: add schema for tracking indexed repositories
smokeyScraper a9d3b8a
[feat]: add codegraph supporting tool as service
smokeyScraper e17a2d3
[update]: prompt updation with adding repo_support tool to toolkit
smokeyScraper 47ff385
[feat]: add / commands to support codegraph repo_support tool for ind…
smokeyScraper d98d49c
[chore]: versioning updates to packages
smokeyScraper 7e99be7
chore(vendor): vendor FalkorDB code-graph-backend
smokeyScraper b7fbdbf
fix: fixed nodes and edges count issue
smokeyScraper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import logging | ||
| import re | ||
| from typing import Dict, Any, Optional | ||
| from app.services.codegraph.repo_service import RepoService | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| async def handle_repo_support(query: str) -> Dict[str, Any]: | ||
| """Handle repository code graph queries.""" | ||
| try: | ||
| service = RepoService() | ||
| repo_name = _extract_repo_name(query) | ||
|
|
||
| if not repo_name: | ||
| return { | ||
| "status": "error", | ||
| "sub_function": "repo_support", | ||
| "message": "Please specify repository: 'Where is X in owner/repo?'" | ||
| } | ||
|
|
||
| result = await service.query_repo(query, repo_name) | ||
|
|
||
| return { | ||
| "status": result["status"], | ||
| "sub_function": "repo_support", | ||
| "repository": repo_name, | ||
| **{k: v for k, v in result.items() if k != "status"} | ||
| } | ||
|
|
||
| except Exception as e: | ||
| logger.exception("Repository support error") | ||
| return { | ||
| "status": "error", | ||
| "sub_function": "repo_support", | ||
| "message": "Query failed. Please try again." | ||
| } | ||
|
|
||
| def _extract_repo_name(query: str) -> Optional[str]: | ||
| """Extract repository name from query (owner/repo format)""" | ||
| pattern = r'\b([a-zA-Z0-9][-a-zA-Z0-9]*)/([a-zA-Z0-9_.-]+)\b' | ||
| match = re.search(pattern, query) | ||
| return match.group(0) if match else None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| FALKORDB_HOST=<host> | ||
| FALKORDB_PORT=<port> | ||
| FALKORDB_USERNAME=<username> | ||
| FALKORDB_PASSWORD=<password> | ||
| OPENAI_API_KEY=<openai_api_key> | ||
| GEMINI_API_KEY=<gemini_api_key> | ||
| SECRET_TOKEN=<secret_token> | ||
|
|
7 changes: 7 additions & 0 deletions
7
backend/app/database/falkor/code-graph-backend/.github/dependabot.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| version: 2 | ||
| updates: | ||
| - package-ecosystem: "pip" # See documentation for possible values | ||
| directory: "/" # Location of package manifests | ||
| schedule: | ||
| interval: "daily" | ||
| target-branch: "staging" |
40 changes: 40 additions & 0 deletions
40
backend/app/database/falkor/code-graph-backend/.github/workflows/python-app.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # This workflow will install Python dependencies, run tests and lint with a single version of Python | ||
| # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python | ||
|
|
||
| name: Python application | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ "main" ] | ||
| pull_request: | ||
| branches: [ "main" ] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| build: | ||
|
|
||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Set up Python 3.10 | ||
| uses: actions/setup-python@v3 | ||
| with: | ||
| python-version: "3.10" | ||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install flake8 pytest | ||
| if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | ||
| - name: Lint with flake8 | ||
| run: | | ||
| # stop the build if there are Python syntax errors or undefined names | ||
| flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | ||
| # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | ||
| # flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | ||
|
|
||
| # - name: Test with pytest | ||
| # run: | | ||
| # pytest |
37 changes: 37 additions & 0 deletions
37
backend/app/database/falkor/code-graph-backend/.github/workflows/release-image.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| name: Release image to DockerHub | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| push: | ||
| tags: ["v*.*.*"] | ||
| branches: | ||
| - main | ||
|
|
||
| jobs: | ||
| build-and-release: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set tags | ||
| run: | | ||
| if ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') }}; then | ||
| echo "TAGS=falkordb/code-graph-backend:latest,falkordb/code-graph-backend:${{ github.ref_name }}" >> $GITHUB_ENV | ||
| else | ||
| echo "TAGS=falkordb/code-graph-backend:edge" >> $GITHUB_ENV | ||
| fi | ||
|
|
||
| - name: Login to DockerHub | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| username: ${{ secrets.DOCKER_USERNAME }} | ||
| password: ${{ secrets.DOCKER_PASSWORD }} | ||
|
|
||
| - name: Build image | ||
| uses: docker/build-push-action@v5 | ||
| with: | ||
| context: . | ||
| file: ./Dockerfile | ||
| push: true | ||
| tags: ${{ env.TAGS }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # Byte-compiled files | ||
| *.pyc | ||
| *.pyo | ||
| *.pyd | ||
| __pycache__/ | ||
|
|
||
| # Virtual environments | ||
| venv/ | ||
| env/ | ||
| .virtualenv/ | ||
|
|
||
| # Distribution/build files | ||
| build/ | ||
| dist/ | ||
| *.egg-info/ | ||
| .eggs/ | ||
|
|
||
| # IDE settings | ||
| .vscode/ | ||
| .idea/ | ||
| *.swp | ||
|
|
||
| # Logs and debugging | ||
| *.log | ||
| *.trace | ||
|
|
||
| # OS-specific files | ||
| .DS_Store | ||
| Thumbs.db | ||
|
|
||
| # Testing and coverage | ||
| htmlcov/ | ||
| *.cover | ||
| .coverage | ||
| .cache/ | ||
| pytest_cache/ | ||
|
|
||
| # Jupyter Notebook checkpoints | ||
| .ipynb_checkpoints/ | ||
|
|
||
| # Custom settings | ||
| .env | ||
| *.sqlite3 | ||
| .vercel |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| MIT License | ||
|
|
||
| Copyright (c) 2024 FalkorDB | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| [](https://app.falkordb.cloud) | ||
| [](https://hub.docker.com/r/falkordb/falkordb/) | ||
| [](https://discord.com/invite/6M4QwDXn2w) | ||
|
|
||
| ## Getting Started | ||
|
|
||
| [Live Demo](https://code-graph.falkordb.com/) | ||
|
|
||
| ## Running locally | ||
|
|
||
| ### Run FalkorDB | ||
|
|
||
| Free cloud instance: https://app.falkordb.cloud/signup | ||
|
|
||
| Or by running locally with docker: | ||
|
|
||
| ```bash | ||
| docker run -p 6379:6379 -p 3000:3000 -it --rm falkordb/falkordb:latest | ||
| ``` | ||
|
|
||
| ### Config | ||
|
|
||
| Create your own `.env` file from the `.env.template` file | ||
|
|
||
| Start the server: | ||
| ```bash | ||
| flask --app api/index.py run --debug | ||
| ``` | ||
|
|
||
| ### Creating a graph | ||
|
|
||
| Process a local source folder: | ||
|
|
||
| ```bash | ||
| curl -X POST http://127.0.0.1:5000/analyze_folder -H "Content-Type: application/json" -d '{"path": "<FULL_PATH_TO_FOLDER>", "ignore": [<OPTIONAL_IGNORE_LIST>]}' -H "Authorization: <.ENV_SECRET_TOKEN>" | ||
| ``` | ||
|
|
||
| For example: | ||
|
|
||
| ```bash | ||
| curl -X POST http://127.0.0.1:5000/analyze_folder -H "Content-Type: application/json" -d '{"path": "/Users/roilipman/Dev/GraphRAG-SDK", "ignore": ["./.github", "./build"]}' -H "Authorization: OpenSesame" | ||
| ``` | ||
smokeyScraper marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Working with your graph | ||
|
|
||
| Once the source code analysis completes your FalkorDB DB will be populated with | ||
| a graph representation of your source code, the graph name should be the same as | ||
| the name of the folder you've requested to analyze, for the example above a graph named: | ||
| "GraphRAG-SDK". | ||
|
|
||
| At the moment only the Python and C languages are supported, we do intend to support additional languages. | ||
|
|
||
| At this point you can explore and query your source code using various tools | ||
| Here are several options: | ||
|
|
||
| 1. [Code-Graph UI](https://github.com/FalkorDB/code-graph) | ||
| 1. FalkorDB [Browser](https://github.com/FalkorDB/falkordb-browser/) | ||
| 2. One of FalkorDB's [clients](https://docs.falkordb.com/clients.html) | ||
| 3. Use FalkorDB [GraphRAG-SDK](https://github.com/FalkorDB/GraphRAG-SDK) to connect an LLM for natural language exploration. | ||
9 changes: 9 additions & 0 deletions
9
backend/app/database/falkor/code-graph-backend/api/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| from .info import * | ||
| from .llm import ask | ||
| from .graph import * | ||
| from .project import * | ||
| from .entities import * | ||
| from .git_utils import * | ||
| from .code_coverage import * | ||
| from .analyzers.source_analyzer import * | ||
| from .auto_complete import prefix_search |
1 change: 1 addition & 0 deletions
1
backend/app/database/falkor/code-graph-backend/api/analyzers/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from .source_analyzer import SourceAnalyzer |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.