Skip to content

Commit acf5344

Browse files
committed
docs: add weighted traversal documentation to README
Document the new weighted traversal feature including: - Scoring algorithm (edge weight, similarity, depth penalty) - Relationship weight tiers - Usage examples and when to disable
1 parent 1c43fb2 commit acf5344

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

README.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ A Model Context Protocol (MCP) server that builds rich code graphs to provide de
1717
- **Semantic Search**: Vector-based semantic search using OpenAI embeddings to find relevant code patterns and implementations
1818
- **Natural Language Querying**: Convert natural language questions into Cypher queries using OpenAI assistants API
1919
- **Framework-Aware & Customizable**: Built-in NestJS schema with ability to define custom framework patterns via configuration
20-
- **Graph Traversal**: Explore code relationships and dependencies through intelligent graph traversal
20+
- **Weighted Graph Traversal**: Intelligent traversal that scores paths based on relationship importance, query relevance, and depth
2121
- **High Performance**: Optimized Neo4j storage with vector indexing for fast retrieval
2222
- **MCP Integration**: Seamless integration with Claude Code and other MCP-compatible tools
2323

@@ -477,6 +477,36 @@ firstDepth.chains.forEach(chain => {
477477
- **Direction Filtering**: Use `direction: "OUTGOING"` or `"INCOMING"` to focus exploration
478478
- **Source Code on Demand**: Source code included by default but truncated to 1000 chars
479479

480+
#### Weighted Traversal
481+
482+
The `search_codebase` tool uses **weighted traversal** by default (`useWeightedTraversal: true`) to intelligently prioritize which relationships to explore. This produces more relevant results by scoring each node at every depth level.
483+
484+
**How Scoring Works**:
485+
486+
Each potential path is scored using three factors multiplied together:
487+
488+
1. **Edge Weight** (0.0-1.0): How important is this relationship type?
489+
- Critical (0.9-0.95): `INJECTS`, `EXPOSES`, `ROUTES_TO` - core architectural relationships
490+
- High (0.8-0.88): `EXTENDS`, `IMPLEMENTS`, `USES_REPOSITORY` - important semantic links
491+
- Medium (0.5-0.6): `IMPORTS`, `EXPORTS`, `HAS_MEMBER` - structural relationships
492+
- Low (0.3-0.4): `DECORATED_WITH`, `HAS_PARAMETER` - metadata relationships
493+
494+
2. **Node Similarity**: Cosine similarity between the node's embedding and your query embedding. Nodes semantically related to your search rank higher.
495+
496+
3. **Depth Penalty**: Exponential decay (default 0.85 per level). Closer nodes are preferred:
497+
- Depth 1: 1.0 (no penalty)
498+
- Depth 2: 0.85
499+
- Depth 3: 0.72
500+
501+
**When to Disable**:
502+
```typescript
503+
// Use standard traversal for exhaustive exploration
504+
search_codebase({
505+
query: "...",
506+
useWeightedTraversal: false
507+
})
508+
```
509+
480510
#### Performance Optimization
481511
- **Token Efficiency**: JSON:API normalization eliminates duplicate nodes in responses
482512
- **Code Truncation**: Source code limited to 1000 chars (first 500 + last 500) to prevent token overflow
@@ -502,7 +532,7 @@ firstDepth.chains.forEach(chain => {
502532

503533
| Tool | Description | Parameters | Best For |
504534
|------|-------------|------------|----------|
505-
| `search_codebase` | **Vector-based semantic search** - Find most relevant code using OpenAI embeddings | `query` (string), `limit?` (default: 10) | **Starting point** for code exploration. Returns comprehensive multi-depth graph starting from best semantic match |
535+
| `search_codebase` | **Vector-based semantic search** - Find most relevant code using OpenAI embeddings | `query`, `limit?`, `useWeightedTraversal?` (default: true) | **Starting point** for code exploration. Uses weighted scoring for intelligent traversal |
506536
| `traverse_from_node` | **Focused graph traversal** - Explore specific relationships from a known node | `nodeId` (string), `maxDepth?` (1-10, default: 3), `skip?` (default: 0) | **Deep diving** into specific code relationships. Pagination for large graphs |
507537
| `natural_language_to_cypher` | **AI-powered query generation** - Convert natural language to Cypher queries using GPT-4 | `query` (string) | **Advanced queries** - currently requires OpenAI assistant setup |
508538

0 commit comments

Comments
 (0)