Skip to content

Commit 831edd5

Browse files
CopilotMte90
andcommitted
Add per-project storage and PyCharm API integration
Co-authored-by: Mte90 <403283+Mte90@users.noreply.github.com>
1 parent 8afabff commit 831edd5

File tree

5 files changed

+855
-7
lines changed

5 files changed

+855
-7
lines changed

PYCHARM_INTEGRATION.md

Lines changed: 333 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,333 @@
1+
# PyCharm Plugin Integration Guide
2+
3+
This document describes the REST API for integrating PicoCode with PyCharm and other IDEs.
4+
5+
## Overview
6+
7+
PicoCode provides a production-ready local RAG backend with per-project persistent storage. Each project gets its own SQLite database for isolation, and the API is designed to be compatible with IDE plugins.
8+
9+
## API Endpoints
10+
11+
### Base URL
12+
```
13+
http://127.0.0.1:8000/api
14+
```
15+
16+
### Health Check
17+
```http
18+
GET /api/health
19+
```
20+
21+
Returns server status and available features.
22+
23+
**Response:**
24+
```json
25+
{
26+
"status": "ok",
27+
"version": "0.2.0",
28+
"features": ["rag", "per-project-db", "pycharm-api"]
29+
}
30+
```
31+
32+
### Project Management
33+
34+
#### Create/Get Project
35+
```http
36+
POST /api/projects
37+
Content-Type: application/json
38+
39+
{
40+
"path": "/absolute/path/to/project",
41+
"name": "Optional Project Name"
42+
}
43+
```
44+
45+
Creates a new project or returns existing one. Each project gets its own database.
46+
47+
**Response:**
48+
```json
49+
{
50+
"id": "1234567890abcdef",
51+
"name": "MyProject",
52+
"path": "/absolute/path/to/project",
53+
"database_path": "~/.picocode/projects/1234567890abcdef.db",
54+
"created_at": "2025-11-06T14:30:00",
55+
"last_indexed_at": null,
56+
"status": "created",
57+
"settings": null
58+
}
59+
```
60+
61+
#### List All Projects
62+
```http
63+
GET /api/projects
64+
```
65+
66+
Returns list of all registered projects.
67+
68+
**Response:**
69+
```json
70+
[
71+
{
72+
"id": "1234567890abcdef",
73+
"name": "MyProject",
74+
"path": "/absolute/path/to/project",
75+
"status": "ready",
76+
...
77+
}
78+
]
79+
```
80+
81+
#### Get Project Details
82+
```http
83+
GET /api/projects/{project_id}
84+
```
85+
86+
Returns details for a specific project.
87+
88+
#### Delete Project
89+
```http
90+
DELETE /api/projects/{project_id}
91+
```
92+
93+
Deletes project and its database.
94+
95+
**Response:**
96+
```json
97+
{
98+
"success": true
99+
}
100+
```
101+
102+
### Indexing
103+
104+
#### Index Project
105+
```http
106+
POST /api/projects/index
107+
Content-Type: application/json
108+
109+
{
110+
"project_id": "1234567890abcdef"
111+
}
112+
```
113+
114+
Starts background indexing of the project. This processes all files, generates embeddings, and stores them in the project's database.
115+
116+
**Response:**
117+
```json
118+
{
119+
"status": "indexing",
120+
"project_id": "1234567890abcdef"
121+
}
122+
```
123+
124+
### Code Intelligence
125+
126+
#### Semantic Search
127+
```http
128+
POST /api/query
129+
Content-Type: application/json
130+
131+
{
132+
"project_id": "1234567890abcdef",
133+
"query": "How does authentication work?",
134+
"top_k": 5
135+
}
136+
```
137+
138+
Performs semantic search across the indexed project.
139+
140+
**Response:**
141+
```json
142+
{
143+
"results": [
144+
{
145+
"file_id": 123,
146+
"path": "src/auth.py",
147+
"chunk_index": 0,
148+
"score": 0.8542
149+
}
150+
],
151+
"project_id": "1234567890abcdef",
152+
"query": "How does authentication work?"
153+
}
154+
```
155+
156+
#### Code Completion / Question Answering
157+
```http
158+
POST /api/code
159+
Content-Type: application/json
160+
161+
{
162+
"project_id": "1234567890abcdef",
163+
"prompt": "Explain the authentication flow",
164+
"context": "",
165+
"use_rag": true,
166+
"top_k": 5
167+
}
168+
```
169+
170+
Gets code suggestions or answers using RAG + LLM.
171+
172+
**Response:**
173+
```json
174+
{
175+
"response": "The authentication flow works as follows...",
176+
"used_context": [
177+
{
178+
"path": "src/auth.py",
179+
"score": 0.8542
180+
}
181+
],
182+
"project_id": "1234567890abcdef"
183+
}
184+
```
185+
186+
## PyCharm Plugin Workflow
187+
188+
### 1. On Project Open
189+
When a project is opened in PyCharm:
190+
```
191+
1. POST /api/projects with project path
192+
2. Store returned project_id
193+
3. Check if project needs indexing (status != "ready")
194+
4. If needed, POST /api/projects/index
195+
```
196+
197+
### 2. Code Assistance
198+
When user requests code help:
199+
```
200+
1. POST /api/code with prompt and project_id
201+
2. Display response in IDE
202+
3. Show used_context sources if available
203+
```
204+
205+
### 3. Semantic Search
206+
When user searches for code:
207+
```
208+
1. POST /api/query with search term and project_id
209+
2. Display matching files and scores
210+
3. Allow navigation to results
211+
```
212+
213+
### 4. Background Monitoring
214+
Poll project status periodically:
215+
```
216+
1. GET /api/projects/{project_id}
217+
2. Check status field
218+
3. Update UI indicators
219+
```
220+
221+
## Configuration
222+
223+
Create a `.env` file with:
224+
225+
```bash
226+
# API endpoint for embeddings and LLM
227+
API_URL=https://api.openai.com/v1/
228+
API_KEY=your-api-key-here
229+
230+
# Model names
231+
EMBEDDING_MODEL=text-embedding-3-small
232+
CODING_MODEL=gpt-4o
233+
234+
# Server configuration
235+
UVICORN_HOST=127.0.0.1
236+
UVICORN_PORT=8000
237+
238+
# File processing
239+
MAX_FILE_SIZE=200000
240+
```
241+
242+
## Error Handling
243+
244+
All endpoints return standard HTTP status codes:
245+
- 200: Success
246+
- 400: Bad request (validation error)
247+
- 404: Resource not found
248+
- 500: Server error
249+
250+
Error responses include a JSON object:
251+
```json
252+
{
253+
"error": "Description of the error"
254+
}
255+
```
256+
257+
## Security Considerations
258+
259+
1. **Local-only**: Server binds to 127.0.0.1 by default (localhost only)
260+
2. **File access**: Only indexed files are accessible
261+
3. **Path validation**: Project paths are validated and normalized
262+
4. **Database isolation**: Each project has separate database
263+
264+
## Performance
265+
266+
- **Concurrent indexing**: Uses thread pool for parallel file processing
267+
- **Connection pooling**: Efficient SQLite connection management
268+
- **Caching**: Analysis results cached to reduce database queries
269+
- **Vector search**: Uses sqlite-vector for fast similarity search
270+
271+
## Limitations
272+
273+
1. Maximum file size: 200KB by default (configurable)
274+
2. Text files only (binary files skipped)
275+
3. Requires OpenAI-compatible embedding API
276+
4. SQLite database per project (not suitable for extremely large projects)
277+
278+
## Example Integration (Python)
279+
280+
```python
281+
import requests
282+
283+
class PicoCodeClient:
284+
def __init__(self, base_url="http://127.0.0.1:8000/api"):
285+
self.base_url = base_url
286+
287+
def create_project(self, path, name=None):
288+
response = requests.post(
289+
f"{self.base_url}/projects",
290+
json={"path": path, "name": name}
291+
)
292+
return response.json()
293+
294+
def index_project(self, project_id):
295+
response = requests.post(
296+
f"{self.base_url}/projects/index",
297+
json={"project_id": project_id}
298+
)
299+
return response.json()
300+
301+
def query(self, project_id, query, top_k=5):
302+
response = requests.post(
303+
f"{self.base_url}/query",
304+
json={
305+
"project_id": project_id,
306+
"query": query,
307+
"top_k": top_k
308+
}
309+
)
310+
return response.json()
311+
312+
def get_code_suggestion(self, project_id, prompt, use_rag=True):
313+
response = requests.post(
314+
f"{self.base_url}/code",
315+
json={
316+
"project_id": project_id,
317+
"prompt": prompt,
318+
"use_rag": use_rag
319+
}
320+
)
321+
return response.json()
322+
323+
# Usage
324+
client = PicoCodeClient()
325+
project = client.create_project("/path/to/my/project", "MyProject")
326+
client.index_project(project["id"])
327+
results = client.query(project["id"], "authentication flow")
328+
suggestion = client.get_code_suggestion(project["id"], "Explain auth")
329+
```
330+
331+
## Support
332+
333+
For issues or questions, please refer to the main PicoCode repository.

README.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,29 @@ This tool is a way to achieve this!
99

1010
## Overview
1111

12-
- Indexes files, computes embeddings using an OpenAI-compatible embedding endpoint, stores data in SQLite (with SQlite-vector).
13-
- Reads dependencies by running `python -m pip list --format=json` inside a virtualenv when available.
14-
- Detects Astral "uv" usage (https://docs.astral.sh/uv/) by inspecting `pyproject.toml` and/or installed packages in a venv; if uv is detected it tries to locate a venv managed by uv and uses it for `pip list`.
15-
- Analysis runs asynchronously (FastAPI BackgroundTasks) so the UI remains responsive.
16-
- Minimal web UI for starting analysis and asking questions (semantic search + coding model).
12+
- **Production-ready RAG backend** with per-project persistent storage
13+
- **PyCharm/IDE integration** via REST API (see [PYCHARM_INTEGRATION.md](PYCHARM_INTEGRATION.md))
14+
- **Per-project databases**: Each project gets isolated SQLite database
15+
- Indexes files, computes embeddings using an OpenAI-compatible embedding endpoint
16+
- Stores vector embeddings in SQLite using sqlite-vector for fast semantic search
17+
- Analysis runs asynchronously (FastAPI BackgroundTasks) so the UI remains responsive
18+
- Minimal web UI for starting analysis and asking questions (semantic search + coding model)
19+
- Health check and monitoring endpoints for production deployment
20+
21+
## New Features (v0.2.0)
22+
23+
### Per-Project Persistent Storage
24+
- Each opened project gets its own SQLite database
25+
- Isolated storage prevents cross-project data leakage
26+
- Project registry tracks all indexed projects
27+
- Automatic project ID generation based on path
28+
29+
### PyCharm Plugin API
30+
- RESTful API designed for IDE integration
31+
- Create/manage projects via API
32+
- Background indexing with status tracking
33+
- Semantic search and code completion endpoints
34+
- See [PYCHARM_INTEGRATION.md](PYCHARM_INTEGRATION.md) for full API documentation
1735

1836
Prerequisites
1937
- Python 3.8+ (3.11+ recommended for builtin tomllib)

0 commit comments

Comments
 (0)