Repository navigation
[BILL-55] Implement SCIP ingestion pipeline (indexers → Cypher MERGE) - #67
Conversation
Behavioural spec for rag_service.code_graph.ingest (pure functions) and POST /code-graph/ingest (endpoint). All tests fail on current code — the ingest module and endpoint do not exist yet. Layer split: test_code_graph_ingest.py (Layer 1, no FastAPI imports) + test_code_graph_ingest_endpoint.py (Layer 2, TestClient + FakeCodeGraphDB). Refs: BILL-55 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds rag_service/code_graph/ingest.py — pure Layer 1 functions: - extract_vertices: File/symbol/External-stub vertices from SCIP JSON - extract_calls_edges: CALLS via enclosing_range containment - extract_implements_edges: IMPLEMENTS from is_implementation relationships - build_vertex_cypher / build_edge_cypher: idempotent Cypher MERGE statements Extends db.py: setup_age_session() + DB.run_cypher(). Adds POST /code-graph/ingest endpoint (main.py + models.py). All 17 Phase-0 red tests now green; existing 166 tests unaffected. Also adds /simplify pre-commit rule to repo-conventions.md. Refs: BILL-55 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds POST /code-graph/ingest: accepts a SCIP JSON index, extracts vertices (File, Function, Method, etc.) and edges (CALLS, IMPLEMENTS), and MERGEs them idempotently into the AGE code_graph. Introduces get_age_conn() — a FastAPI dependency provider that calls setup_age_session() before yielding, so only the ingest endpoint (and future AGE-query endpoints) pay the LOAD 'age' + SET search_path overhead. get_db_conn() no longer calls setup_age_session; /healthz and /search are unaffected. Both providers share _yield_db_conn() to avoid duplicated connection-lifecycle logic. Adds verify-bill55.sh: 6-check Docker smoke test covering boot readiness, ingest 200 response, vertex/edge counts, AGE graph persistence, idempotent re-ingest, and no fatal log markers. Refs: BILL-55 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThis PR implements SCIP index ingestion (BILL-55): pure transformation functions that emit idempotent AGE/Cypher, AGE DB session and run_cypher support, a FastAPI POST /code-graph/ingest endpoint, unit and integration tests, and a Docker acceptance verification script. Adds a repo convention to run ChangesSCIP Ingestion Pipeline
Sequence DiagramsequenceDiagram
participant Client as HTTP Client
participant Endpoint as POST /code-graph/ingest
participant extract_v as extract_vertices()
participant extract_calls as extract_calls_edges()
participant extract_impl as extract_implements_edges()
participant build_v as build_vertex_cypher()
participant build_e as build_edge_cypher()
participant DB as DB.run_cypher()
participant AGE as PostgreSQL/AGE
Client->>Endpoint: repo, SCIP index
Endpoint->>extract_v: index, repo
Endpoint->>extract_calls: index, repo
Endpoint->>extract_impl: index, repo
extract_v->>build_v: vertex dicts
extract_calls->>build_e: calls tuples
extract_impl->>build_e: implements tuples
build_v->>DB: MERGE vertex cypher
build_e->>DB: MERGE edge cypher
DB->>AGE: execute cypher via SQL wrapper
AGE->>DB: result rows
DB->>Endpoint: merged counts
Endpoint->>Client: {vertices_merged, edges_merged}
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docker/postgres-pgvector/verify-bill55.sh`:
- Around line 163-169: The docker run call currently swallows output and exit
status; before calling wait_uvicorn_ge, capture and check the exit status of
docker run (invocation using variables CONTAINER, DATA_DIR, IMAGE) and fail fast
if it failed: verify the run returned 0, print or log the container ID or docker
logs (or use docker ps to confirm the container is running) and call
process/exit with a clear error message if not; only proceed to call
wait_uvicorn_ge 1 60 when the docker run succeeded.
In `@rag-service/rag_service/code_graph/ingest.py`:
- Around line 86-93: The _wrap_cypher function is vulnerable because it injects
untagged $$-delimited Cypher into SQL; fix by eliminating untagged
dollar-quoting for user-derived content: either switch to parameterized
execution via AGE prepared statements (use DB.run_cypher/cur.execute with a
parameter map or the cypher() third-argument parameter to pass repo/index as
agtype params) or construct a collision-resistant tagged dollar-quote delimiter
and validate/reject any input containing that exact tag; also ensure _cypher_str
is used only for Cypher single-quoted literals (not for wrapping the whole $$
block) and update DB.run_cypher call sites to send the raw cypher template plus
parameters instead of interpolating user values into the $$ block.
In `@rag-service/rag_service/db.py`:
- Around line 346-357: The generator currently sets conn.autocommit = True and
calls setup_age_session(conn) before the try/finally that yields DB(conn=conn),
so if setup_age_session raises the connection is never closed; move the
conn.autocommit = True and setup_age_session(conn) calls inside the same try
block that yields DB(conn=conn) (i.e., after successful psycopg.connect and
before yield but within the try/finally that contains the yield) so that the
finally always runs conn.close() even if setup_age_session fails; keep the
existing except psycopg.OperationalError branch that yields DB(conn=None) and
returns.
In `@rag-service/rag_service/main.py`:
- Around line 118-123: ingest_code_graph currently issues db.run_cypher per
vertex/edge using get_age_conn() with autocommit, causing non-atomic partial
writes and many round-trips; change it to open an explicit AGE transaction for
the entire ingest (disable autocommit for that request or use a transactional
connection) so failures roll back the whole request, and batch writes by
grouping vertices by label and edges by edge_type and execute a single UNWIND +
MERGE Cypher per group (use parameterized $items lists passed to db.run_cypher
and keep the current per-field SET semantics rather than SET v = $map) instead
of calling build_vertex_cypher/build_edge_cypher repeatedly; ensure you commit
on success and rollback on exception and update ingest_code_graph, get_age_conn
usage, and any callers accordingly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 955c5f56-4e32-41d8-8aad-fd4e6cb8cd14
📒 Files selected for processing (8)
.claude/rules/repo-conventions.mddocker/postgres-pgvector/verify-bill55.shrag-service/rag_service/code_graph/ingest.pyrag-service/rag_service/db.pyrag-service/rag_service/main.pyrag-service/rag_service/models.pyrag-service/tests/test_code_graph_ingest.pyrag-service/tests/test_code_graph_ingest_endpoint.py
| docker run -d \ | ||
| --name "$CONTAINER" \ | ||
| -v "$DATA_DIR:/var/lib/postgresql" \ | ||
| "$IMAGE" >/dev/null 2>&1 | ||
|
|
||
| check "fresh-volume boot: app ready (uvicorn up, schema applied) within 60s" \ | ||
| wait_uvicorn_ge 1 60 |
There was a problem hiding this comment.
Check docker run succeeded before waiting on Uvicorn.
The container launch discards output and ignores its exit status. If the image is missing or fails to start, the failure surfaces only as a confusing 60s wait_uvicorn_ge timeout rather than an immediate, clear error.
🩹 Suggested guard
note "Fresh-volume boot"
-docker run -d \
- --name "$CONTAINER" \
- -v "$DATA_DIR:/var/lib/postgresql" \
- "$IMAGE" >/dev/null 2>&1
+if ! docker run -d \
+ --name "$CONTAINER" \
+ -v "$DATA_DIR:/var/lib/postgresql" \
+ "$IMAGE" >/dev/null 2>&1; then
+ echo " FAIL could not start container from image $IMAGE"
+ exit 1
+fi📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| docker run -d \ | |
| --name "$CONTAINER" \ | |
| -v "$DATA_DIR:/var/lib/postgresql" \ | |
| "$IMAGE" >/dev/null 2>&1 | |
| check "fresh-volume boot: app ready (uvicorn up, schema applied) within 60s" \ | |
| wait_uvicorn_ge 1 60 | |
| if ! docker run -d \ | |
| --name "$CONTAINER" \ | |
| -v "$DATA_DIR:/var/lib/postgresql" \ | |
| "$IMAGE" >/dev/null 2>&1; then | |
| echo " FAIL could not start container from image $IMAGE" | |
| exit 1 | |
| fi | |
| check "fresh-volume boot: app ready (uvicorn up, schema applied) within 60s" \ | |
| wait_uvicorn_ge 1 60 |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@docker/postgres-pgvector/verify-bill55.sh` around lines 163 - 169, The docker
run call currently swallows output and exit status; before calling
wait_uvicorn_ge, capture and check the exit status of docker run (invocation
using variables CONTAINER, DATA_DIR, IMAGE) and fail fast if it failed: verify
the run returned 0, print or log the container ID or docker logs (or use docker
ps to confirm the container is running) and call process/exit with a clear error
message if not; only proceed to call wait_uvicorn_ge 1 60 when the docker run
succeeded.
| for vertex in vertices: | ||
| db.run_cypher(build_vertex_cypher(vertex)) | ||
|
|
||
| all_edges = calls_edges + implements_edges | ||
| for src, edge_type, tgt in all_edges: | ||
| db.run_cypher(build_edge_cypher(src, edge_type, tgt, req.repo)) |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
Apache AGE cypher UNWIND parameters batch MERGE agtype
💡 Result:
Apache AGE supports UNWIND + MERGE for batching and parameterized inputs, but it does not reliably support the Neo4j-like pattern of setting an entire vertex property map via SET v = $param (or sometimes SET v = row) in prepared-statement/parameter contexts. The recommended approach is to UNWIND your parameter list/map into per-row attributes, then either (a) set individual keys, or (b) use SET v = attributes only if your AGE version has the relevant fix; otherwise you must assign keys explicitly. 1) UNWIND basics (for batching) UNWIND expands a list into multiple rows; in AGE it produces a single row with a null variable when the expression is NULL, and no rows when the list is empty [1]. 2) MERGE basics (for upserts) MERGE ensures a pattern exists; it matches existing nodes/edges or creates them if missing [2]. 3) Prepared statements parameter passing (agtype) With AGE cypher(graph_name, query_string, parameters), the optional parameters argument is a map used for Prepared Statements [3]. Prepared-statement execution expects an agtype map (not a plain SQL type), and the docs show passing JSON-ish text as an agtype string representation (e.g., '{"name": "Tobias"}') [4]. 4) Why SET p = $param / SET v = row is problematic - A Stack Overflow report shows SET p1 = $person (with parameters used via AGE prepared-statement plumbing) fails with error “SET clause expects a map”, and suggests using UNWIND as a workaround [5]. - GitHub issue #1634 reports that setting “all properties with map object” using SET v=map errors (e.g., properties() argument must resolve to a scalar value), while setting with explicit keys (e.g., SET v.first=map.first, v.last=map.last) works, and setting with a literal map works [6]. - GitHub issue #2167 similarly reports an error when using UNWIND and then SET s = row in a parameterized/batched scenario; it notes this was fixed in master/unreleased branches and points to a dev snapshot as a workaround (so behavior is version-dependent) [7]. So: if your goal is “batch MERGE and set properties from a parameter map”, the robust pattern is to UNWIND the incoming list into rows (each row being an attributes map), then SET properties in a way that your AGE version supports. 5) Practical batching pattern (recommended) A) If you can set the whole map (version-dependent; may fail in some versions) Use UNWIND over a parameter list and then MERGE + SET. Example pattern (from the UNWIND+SET/ prepared-statement workaround described on Stack Overflow): - PREPARE an AGE function that receives an agtype parameter containing a list under a key (e.g., data) - UNWIND that list into attributes - CREATE/merge a node and set p = attributes The Stack Overflow answer shows: UNWIND $data AS attributes CREATE (p:Person) SET p = attributes inside a prepared statement [5]. B) Most robust across AGE versions: set keys explicitly If SET v = attributes fails in your version, set properties individually from the unwound attributes map (as in issue #1634 workaround) [6]. 6) Concrete upsert+batch template (works reliably) Use UNWIND to process a list of objects, and MERGE on a stable identity property, then set fields explicitly: SELECT * FROM cypher('graph', $$ UNWIND $items/keys with your actual parameter structure.) 7) “UNWIND parameters batch MERGE agtype” summary - Batch parameters: pass an agtype parameter map into cypher(...) in prepared statements [3][4]. - Expand list batches: use UNWIND over a list parameter to get one row per element [1]. - Upsert: use MERGE for identity-based upserts [2]. - Property map assignment: avoid assuming SET n = $param or SET n = row will work in all AGE versions; if it errors, set properties key-by-key instead [5][6][7].
Citations:
- 1: https://age.apache.org/age-manual/master/clauses/unwind.html
- 2: https://age.apache.org/age-manual/master/clauses/merge.html
- 3: https://age.apache.org/age-manual/master/intro/cypher.html
- 4: https://age.apache.org/age-manual/master/advanced/prepared_statements.html
- 5: https://stackoverflow.com/questions/79838116/why-does-set-p1-person-in-apache-age-cypher-return-set-clause-expects-a-map
- 6: Setting all properties with map object causes error apache/age#1634
- 7: Dynamically unpacking properties with UNWIND and SET s = row fails with Error: properties() argument must resolve to a scalar value apache/age#2167
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Locate and inspect relevant code in rag-service/rag_service/main.py
ls -R
rg -n "def get_age_conn|get_age_conn|autocommit" -S rag-service/rag_service || true
rg -n "def build_vertex_cypher|build_vertex_cypher|def build_edge_cypher|build_edge_cypher|run_cypher" -S rag-service/rag_service || true
echo "---- main.py excerpt around 100-150 ----"
python3 - <<'PY'
import pathlib
p = pathlib.Path("rag-service/rag_service/main.py")
lines = p.read_text().splitlines()
start, end = 90, 160
for i in range(start, min(end, len(lines))):
print(f"{i+1:4d}: {lines[i]}")
PYRepository: iansmith/slopstop
Length of output: 6470
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "---- rag-service/rag_service/db.py excerpt around autocommit + run_cypher ----"
python3 - <<'PY'
import pathlib
p = pathlib.Path("rag-service/rag_service/db.py")
lines = p.read_text().splitlines()
for start,end in [(220,310),(320,430)]:
print(f"\n### lines {start+1}-{end}")
for i in range(start, min(end, len(lines))):
print(f"{i+1:4d}: {lines[i]}")
PY
echo "---- rag-service/rag_service/code_graph/ingest.py excerpt around build_vertex_cypher/build_edge_cypher ----"
python3 - <<'PY'
import pathlib
p = pathlib.Path("rag-service/rag_service/code_graph/ingest.py")
lines = p.read_text().splitlines()
# show around function definitions
for start,end in [(200,310),(230,330),(240,310),(260,315)]:
print(f"\n### lines {start+1}-{end}")
for i in range(start, min(end, len(lines))):
print(f"{i+1:4d}: {lines[i]}")
PYRepository: iansmith/slopstop
Length of output: 16376
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "---- locate _wrap_cypher / injection comment in ingest.py ----"
rg -n "_wrap_cypher|injection|parameter|agtype|prepared|cypher\\('graph'|cypher\\(\"graph'" -S rag-service/rag_service/code_graph/ingest.py || true
echo "---- ingest.py excerpt around _wrap_cypher and helpers ----"
python3 - <<'PY'
import pathlib, re
p = pathlib.Path("rag-service/rag_service/code_graph/ingest.py")
lines = p.read_text().splitlines()
# Print around occurrences of _wrap_cypher definition
for idx,line in enumerate(lines):
if "def _wrap_cypher" in line:
start=max(0, idx-40); end=min(len(lines), idx+40)
for i in range(start,end):
print(f"{i+1:4d}: {lines[i]}")
break
else:
print("No def _wrap_cypher found")
PY
echo "---- ingest.py excerpt around top of file for comments ----"
python3 - <<'PY'
import pathlib
p = pathlib.Path("rag-service/rag_service/code_graph/ingest.py")
lines = p.read_text().splitlines()
for start,end in [(1,120),(120,200)]:
print(f"\n### lines {start+1}-{end}")
for i in range(start,end):
if i>=len(lines): break
print(f"{i+1:4d}: {lines[i]}")
PYRepository: iansmith/slopstop
Length of output: 12135
🏁 Script executed:
#!/bin/bash
set -euo pipefail
rg -n "injection|inject|parameteriz|prepared statement|agtype|UNWIND|UNWIND\\s+\\$|set\\s+v\\s*=|SET\\s+\\w+\\s*=\\s*\\w+|\\$\\d|%\\(|bind" -S rag-service/rag_service/code_graph/ingest.py || true
rg -n "injection|inject|parameteriz|prepared statement|agtype|UNWIND" -S rag-service/rag_service | head -n 50 || true
# Also inspect any comments around where values are embedded for cypher literals
rg -n "_cypher_str\\(|Escape a value|Escape" -S rag-service/rag_service/code_graph/ingest.pyRepository: iansmith/slopstop
Length of output: 2690
Make /code-graph/ingest atomic and batch AGE writes to avoid thousands of sequential round-trips.
get_age_conn() runs with conn.autocommit = True, and ingest_code_graph() executes one DB.run_cypher() per vertex and per edge (no explicit transaction boundary). Consequences:
- A failure mid-loop leaves a partially ingested graph (no all-or-nothing semantics).
MERGEkeeps retries idempotent, but a single request still has no consistency boundary. - Statement-per-entity scales poorly for large indexes:
len(vertices) + len(all_edges)sequential Cypher executions.
Consider:
- Use an explicit transaction for the ingest request (disable autocommit for that request / use a non-autocommit AGE dependency) so failures roll back the whole ingest.
- Batch with
UNWIND $items+MERGE(per label / edge type) to cut round trips; when setting properties from unwound rows, keep the current robust “key-by-keySET v.<field> = ...” approach rather than relying onSET v = $map/rowbehavior across AGE versions.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@rag-service/rag_service/main.py` around lines 118 - 123, ingest_code_graph
currently issues db.run_cypher per vertex/edge using get_age_conn() with
autocommit, causing non-atomic partial writes and many round-trips; change it to
open an explicit AGE transaction for the entire ingest (disable autocommit for
that request or use a transactional connection) so failures roll back the whole
request, and batch writes by grouping vertices by label and edges by edge_type
and execute a single UNWIND + MERGE Cypher per group (use parameterized $items
lists passed to db.run_cypher and keep the current per-field SET semantics
rather than SET v = $map) instead of calling
build_vertex_cypher/build_edge_cypher repeatedly; ensure you commit on success
and rollback on exception and update ingest_code_graph, get_age_conn usage, and
any callers accordingly.
Move conn.autocommit + setup_age_session() inside the try/finally in _yield_db_conn so conn.close() is guaranteed even if LOAD 'age' raises. Replace untagged $$ dollar-quote delimiter in _wrap_cypher with $scip$, and add a ValueError guard in _cypher_str so a repo or moniker containing $scip$ is rejected before it can break out of the SQL literal. Refs: BILL-55 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
rag-service/rag_service/code_graph/ingest.py (1)
250-252:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winIMPLEMENTs edge targets may not have matching vertices (edges_merged can overcount and edges can be dropped)
extract_implements_edgescreatesIMPLEMENTStargets fromrel["symbol"](relationship target), butextract_verticesonly creates External stub vertices for monikers found indocuments[].occurrences—not from relationship targets.build_edge_cypherthenMATCHes both endpoints by(moniker, repo)beforeMERGE; if the target vertex wasn’t emitted, theMERGEwon’t run and the edge is effectively dropped. Meanwhileingest_code_graphreportsedges_merged=len(all_edges)(extracted edges), not the number of edges actually created.Current unit tests cover the happy path where the
_SHAPEtarget exists indocuments[].symbols, but there’s no fixture asserting behavior when anis_implementationtarget is missing.Please confirm whether
is_implementationrelationship targets are guaranteed to be emitted as vertices by the in-scope indexers (scip-go/python/typescript). If not guaranteed, create External stubs (or otherwise ensure vertices exist) for relationship target monikers and/or baseedges_mergedon DB cypher results.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@rag-service/rag_service/code_graph/ingest.py` around lines 250 - 252, extract_implements_edges is emitting IMPLEMENTS edges using rel["symbol"] as the target while extract_vertices only creates External stub vertices from documents[].occurrences, so IMPLEMENTS targets can be missing and edges dropped while ingest_code_graph still reports edges_merged=len(all_edges); update extract_implements_edges (or the vertex emission pipeline) to ensure a matching vertex is created for each rel["symbol"] used as an IMPLEMENTS target (e.g., emit an External vertex/stub for that moniker/repo when encountering is_implementation relationships), or alternatively change ingest_code_graph to compute edges_merged from the DB cypher result instead of len(all_edges); reference functions: extract_implements_edges, extract_vertices, build_edge_cypher, ingest_code_graph and constant EDGE_IMPLEMENTS when implementing the fix.
🧹 Nitpick comments (1)
rag-service/rag_service/code_graph/ingest.py (1)
293-298: Consider an AGE property index on(moniker, repo)for the edge MATCH.The generated edge Cypher matches both endpoints by
moniker/repowith no vertex label, which forces a full-graph scan twice per edge. During ingestion this runs once per edge (seemain.pyloop), so on larger indexes the cost can approach O(edges × vertices). Creating an index on themoniker(and/orrepo) property in thecode_graphgraph would make these lookups far cheaper without changing the transformation logic.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@rag-service/rag_service/code_graph/ingest.py` around lines 293 - 298, The Cypher in variable cypher uses MATCH on nodes by properties PROP_MONIKER and PROP_REPO (matching src/tgt via src, tgt, r and creating edge_type) which causes full-graph scans; add a property index in the AGE graph (code_graph) on the moniker property (and optionally repo) so these MATCH lookups use the index during ingestion; create the AGE index for the property names used by PROP_MONIKER/PROP_REPO in the code_graph graph (or document running the equivalent CREATE INDEX command prior to ingestion) to avoid O(edges×vertices) scans.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@rag-service/rag_service/code_graph/ingest.py`:
- Around line 250-252: extract_implements_edges is emitting IMPLEMENTS edges
using rel["symbol"] as the target while extract_vertices only creates External
stub vertices from documents[].occurrences, so IMPLEMENTS targets can be missing
and edges dropped while ingest_code_graph still reports
edges_merged=len(all_edges); update extract_implements_edges (or the vertex
emission pipeline) to ensure a matching vertex is created for each rel["symbol"]
used as an IMPLEMENTS target (e.g., emit an External vertex/stub for that
moniker/repo when encountering is_implementation relationships), or
alternatively change ingest_code_graph to compute edges_merged from the DB
cypher result instead of len(all_edges); reference functions:
extract_implements_edges, extract_vertices, build_edge_cypher, ingest_code_graph
and constant EDGE_IMPLEMENTS when implementing the fix.
---
Nitpick comments:
In `@rag-service/rag_service/code_graph/ingest.py`:
- Around line 293-298: The Cypher in variable cypher uses MATCH on nodes by
properties PROP_MONIKER and PROP_REPO (matching src/tgt via src, tgt, r and
creating edge_type) which causes full-graph scans; add a property index in the
AGE graph (code_graph) on the moniker property (and optionally repo) so these
MATCH lookups use the index during ingestion; create the AGE index for the
property names used by PROP_MONIKER/PROP_REPO in the code_graph graph (or
document running the equivalent CREATE INDEX command prior to ingestion) to
avoid O(edges×vertices) scans.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 846599c0-13c3-4349-b399-27514cd73a42
📒 Files selected for processing (2)
rag-service/rag_service/code_graph/ingest.pyrag-service/rag_service/db.py
🚧 Files skipped from review as they are similar to previous changes (1)
- rag-service/rag_service/db.py
Follow-up for BILL-58: atomic ingest + UNWIND batchingCodeRabbit flagged (🟡, deferred) that Why deferred: What BILL-58 should do when it builds the query surface:
The louis14 graph is ~24K CALLS edges; at the current one-round-trip-per-edge rate that's a meaningful ingest time. Batching by label/edge-type should cut it to O(number of distinct labels + edge types) round trips. |
Summary
POST /code-graph/ingestendpoint: accepts a SCIP JSON index, extracts vertices (File, Function, Method, Class, etc.) and edges (CALLS, IMPLEMENTS), and MERGEs them idempotently into the Apache AGEcode_graphget_age_conn()FastAPI dependency provider so only AGE endpoints pay theLOAD 'age'+SET search_pathsetup cost;/healthzand/searchare unaffectedverify-bill55.sh: 6-check Docker smoke test covering boot readiness, ingest 200 response, vertex/edge counts, AGE graph persistence, idempotent re-ingest, and no fatal log markersTicket
BILL-55 — #59
Test plan
rag-service/.venv/bin/pytest— 183 passed, 2 pre-existing skips (model weights absent locally)bash docker/postgres-pgvector/verify-bill55.sh— 6/6 checks pass against rebuilt imagerag_service/db.py—get_db_connandget_age_connshare_yield_db_conn; both providers override correctly in testsrag_service/main.py—/code-graph/ingestdepends onget_age_conn; all other endpoints depend onget_db_conntests/test_code_graph_ingest_endpoint.py—cg_clientfixture overridesget_age_connMERGEsemantics (confirmed by smoke test check 5)🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Documentation
/simplifyfindings.Tests