Skip to content

Commit 3ce4b67

Browse files
committed
shifted to pgvector, added docker, CI/CD and improved indexing
1 parent 97f4f05 commit 3ce4b67

15 files changed

Lines changed: 415 additions & 51 deletions

File tree

.dockerignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.git
2+
backend/.venv
3+
backend/storage
4+
frontend/.next
5+
frontend/node_modules
6+
**/__pycache__
7+
**/*.pyc

.github/workflows/ci.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
backend:
11+
runs-on: ubuntu-latest
12+
services:
13+
postgres:
14+
image: pgvector/pgvector:pg16
15+
env:
16+
POSTGRES_DB: codeassist
17+
POSTGRES_USER: codeassist
18+
POSTGRES_PASSWORD: codeassist
19+
ports:
20+
- 5432:5432
21+
options: >-
22+
--health-cmd "pg_isready -U codeassist -d codeassist"
23+
--health-interval 5s
24+
--health-timeout 5s
25+
--health-retries 10
26+
env:
27+
DATABASE_URL: postgresql://codeassist:codeassist@localhost:5432/codeassist
28+
STORAGE_DIR: storage
29+
steps:
30+
- uses: actions/checkout@v4
31+
- uses: actions/setup-python@v5
32+
with:
33+
python-version: "3.12"
34+
- name: Install backend dependencies
35+
working-directory: backend
36+
run: pip install -r requirements.txt
37+
- name: Compile backend
38+
run: python -m compileall backend/app
39+
40+
frontend:
41+
runs-on: ubuntu-latest
42+
steps:
43+
- uses: actions/checkout@v4
44+
- uses: actions/setup-node@v4
45+
with:
46+
node-version: "22"
47+
cache: npm
48+
cache-dependency-path: frontend/package-lock.json
49+
- name: Install frontend dependencies
50+
working-directory: frontend
51+
run: npm ci
52+
- name: Lint frontend
53+
working-directory: frontend
54+
run: npm run lint
55+
- name: Build frontend
56+
working-directory: frontend
57+
env:
58+
NEXT_PUBLIC_API_BASE_URL: http://localhost:8000
59+
run: npm run build

.github/workflows/deploy.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Deploy
2+
3+
on:
4+
workflow_dispatch:
5+
6+
permissions:
7+
contents: read
8+
id-token: write
9+
10+
jobs:
11+
build-and-push:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: aws-actions/configure-aws-credentials@v4
16+
with:
17+
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
18+
aws-region: ${{ vars.AWS_REGION }}
19+
- uses: aws-actions/amazon-ecr-login@v2
20+
id: ecr-login
21+
22+
- name: Build and push backend image
23+
env:
24+
REGISTRY: ${{ steps.ecr-login.outputs.registry }}
25+
REPOSITORY: ${{ vars.ECR_BACKEND_REPOSITORY }}
26+
IMAGE_TAG: ${{ github.sha }}
27+
run: |
28+
docker build -t "$REGISTRY/$REPOSITORY:$IMAGE_TAG" ./backend
29+
docker push "$REGISTRY/$REPOSITORY:$IMAGE_TAG"
30+
31+
- name: Build and push frontend image
32+
env:
33+
REGISTRY: ${{ steps.ecr-login.outputs.registry }}
34+
REPOSITORY: ${{ vars.ECR_FRONTEND_REPOSITORY }}
35+
IMAGE_TAG: ${{ github.sha }}
36+
NEXT_PUBLIC_API_BASE_URL: ${{ vars.NEXT_PUBLIC_API_BASE_URL }}
37+
run: |
38+
docker build \
39+
--build-arg NEXT_PUBLIC_API_BASE_URL="$NEXT_PUBLIC_API_BASE_URL" \
40+
-t "$REGISTRY/$REPOSITORY:$IMAGE_TAG" \
41+
./frontend
42+
docker push "$REGISTRY/$REPOSITORY:$IMAGE_TAG"

README.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ A GitHub repository understanding assistant. Paste a repo URL, index the source
77
- Frontend: Next.js, Tailwind CSS
88
- Backend: FastAPI
99
- RAG: LangChain, OpenAI
10-
- Vector store: ChromaDB for the MVP
10+
- Vector store: PostgreSQL + pgvector
1111
- Repository processing: GitPython
1212

1313
## Project Layout
@@ -33,6 +33,12 @@ codebase-assistant/
3333

3434
## Backend Setup
3535

36+
Start Postgres with pgvector first:
37+
38+
```bash
39+
docker compose up -d postgres
40+
```
41+
3642
```bash
3743
cd backend
3844
python -m venv .venv
@@ -59,6 +65,8 @@ OPENAI_CHAT_MODEL=gpt-4o-mini
5965
OLLAMA_BASE_URL=http://localhost:11434
6066
LLAMA_CHAT_MODEL=llama3.1 or llama3.2:1b
6167
OLLAMA_TIMEOUT_SECONDS=300
68+
DATABASE_URL=postgresql://codeassist:codeassist@localhost:5432/codeassist
69+
STORAGE_DIR=storage
6270
```
6371

6472
If OpenAI is not configured, OpenAI mode falls back to local hash embeddings and returns relevant chunks instead of a synthesized answer. If Local Llama is selected but Ollama is not running, the app also returns the relevant chunks with setup guidance.
@@ -90,6 +98,20 @@ Frontend runs at:
9098
http://localhost:3000
9199
```
92100

101+
## Docker Compose
102+
103+
Run the full app with PostgreSQL/pgvector:
104+
105+
```bash
106+
docker compose up --build
107+
```
108+
109+
Services:
110+
111+
- Frontend: `http://localhost:3000`
112+
- Backend: `http://localhost:8000`
113+
- Postgres/pgvector: `localhost:5432`
114+
93115
## API
94116

95117
### Index a repository
@@ -158,7 +180,6 @@ Chunk metadata:
158180

159181
## Notes
160182

161-
- ChromaDB is used for the MVP because it is quick to run locally.
162-
- The vector database is persisted under `backend/storage/chroma`.
163-
- Cloned repositories are stored under `backend/storage/repos`.
164-
- Tree-sitter and pgvector are natural next steps once the MVP behavior is proven.
183+
- PostgreSQL with pgvector stores repos, files, chunks, metadata, and vectors.
184+
- Cloned repositories are stored under `STORAGE_DIR/repos`.
185+
- Tree-sitter chunking, background jobs, private repo auth, evals, and CI/CD deployment are natural next steps.

backend/.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
OPENAI_API_KEY=
22
OPENAI_EMBEDDING_MODEL=text-embedding-3-small
33
OPENAI_CHAT_MODEL=gpt-4o-mini
4+
DATABASE_URL=postgresql://codeassist:codeassist@localhost:5432/codeassist
5+
STORAGE_DIR=storage
6+
OLLAMA_BASE_URL=http://localhost:11434
7+
LLAMA_CHAT_MODEL=llama3.1
8+
OLLAMA_TIMEOUT_SECONDS=300

backend/Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM python:3.12-slim
2+
3+
WORKDIR /app
4+
5+
RUN apt-get update \
6+
&& apt-get install -y --no-install-recommends git \
7+
&& rm -rf /var/lib/apt/lists/*
8+
9+
COPY requirements.txt .
10+
RUN pip install --no-cache-dir -r requirements.txt
11+
12+
COPY app ./app
13+
14+
EXPOSE 8000
15+
16+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]

backend/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Backend
22

3-
FastAPI service for cloning repositories, chunking code, embedding chunks, storing vectors in ChromaDB, retrieving relevant chunks, and generating answers.
3+
FastAPI service for cloning repositories, chunking code, embedding chunks, storing vectors in PostgreSQL/pgvector, retrieving relevant chunks, and generating answers.
44

55
The API supports two AI providers:
66

@@ -19,6 +19,7 @@ If local answers time out on slower machines, set `OLLAMA_TIMEOUT_SECONDS=300` o
1919
Run from this folder:
2020

2121
```bash
22+
docker compose up -d postgres
2223
python -m venv .venv
2324
.venv\Scripts\activate
2425
pip install -r requirements.txt

backend/app/api/repo_routes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def index_repository(payload: RepoIndexRequest) -> RepoIndexResponse:
2020
chunks = chunk_files(repo_id, files)
2121
VectorStore(embedding_service=EmbeddingService(provider=payload.ai_provider)).replace_repo_chunks(
2222
repo_id,
23+
repo_url,
2324
chunks,
2425
)
2526
except Exception as exc:

backend/app/core/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

backend/app/core/settings.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import os
2+
from pathlib import Path
3+
4+
5+
DATABASE_URL = os.getenv(
6+
"DATABASE_URL",
7+
"postgresql://codeassist:codeassist@localhost:5432/codeassist",
8+
)
9+
STORAGE_DIR = Path(os.getenv("STORAGE_DIR", "storage"))
10+
REPO_STORAGE_DIR = STORAGE_DIR / "repos"

0 commit comments

Comments
 (0)