Labsco
tecnomanu logo

PAMPA

β˜… 29

from tecnomanu

An MCP server for intelligent semantic search and automatic learning within codebases, allowing AI agents to efficiently query and index project artifacts.

πŸ”₯πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedAccount requiredNeeds API keys

PAMPA – Protocol for Augmented Memory of Project Artifacts

Version 1.12.x Β· Semantic Search Β· MCP Compatible Β· Node.js

<p align="center"> <img src="assets/pampa_banner.jpg" alt="Agent Rules Kit Logo" width="729" /> </p> <p align="center"> <img src="https://img.shields.io/npm/v/pampa.svg" alt="Version" /> <img src="https://img.shields.io/npm/dm/pampa.svg" alt="Downloads" /> <img src="https://img.shields.io/github/license/tecnomanu/pampa" alt="License" /> <img src="https://img.shields.io/github/last-commit/tecnomanu/pampa" alt="Last Commit" /> <img src="https://img.shields.io/github/actions/workflow/status/tecnomanu/pampa/CI" alt="Build Status" /> </p>

Give your AI agents an always-updated, queryable memory of any codebase – with intelligent semantic search and automatic learning – in one npx command.

πŸ‡ͺπŸ‡Έ VersiΓ³n en EspaΓ±ol | πŸ‡ΊπŸ‡Έ English Version | πŸ€– Agent Version

🌟 What's New in v1.12 - Advanced Search & Multi-Project Support

🎯 Scoped Search Filters - Filter by path_glob, tags, lang for precise results

πŸ”„ Hybrid Search - BM25 + Vector fusion with reciprocal rank blending (enabled by default)

🧠 Cross-Encoder Re-Ranker - Transformers.js reranker for precision boosts

πŸ‘€ File Watcher - Real-time incremental indexing with Merkle-like hashing

πŸ“¦ Context Packs - Reusable search scopes with CLI + MCP integration

πŸ› οΈ Multi-Project CLI - --project and --directory aliases for clarity

πŸ† Performance Analysis - Architectural comparison with general-purpose IDE tools

Major improvements:

  • 40% faster indexing with incremental updates
  • 60% better precision with hybrid search + reranker
  • 3x faster multi-project operations with explicit paths
  • 90% reduction in duplicate function creation with symbol boost
  • Specialized architecture for semantic code search

🌟 Why PAMPA?

Large language model agents can read thousands of tokens, but projects easily reach millions of characters. Without an intelligent retrieval layer, agents:

  • Recreate functions that already exist
  • Misname APIs (newUser vs. createUser)
  • Waste tokens loading repetitive code (vendor/, node_modules/...)
  • Fail when the repository grows

PAMPA solves this by turning your repository into a semantic code memory graph:

  1. Chunking – Each function/class becomes an atomic chunk
  2. Semantic Tagging – Automatic extraction of semantic tags from code context
  3. Embedding – Enhanced chunks are vectorized with advanced embedding models
  4. Learning – System learns from successful searches and caches intentions
  5. Indexing – Vectors + semantic metadata live in local SQLite
  6. Codemap – A lightweight pampa.codemap.json commits to git so context follows the repo
  7. Serving – An MCP server exposes intelligent search and retrieval tools

Any MCP-compatible agent (Cursor, Claude, etc.) can now search with natural language, get instant responses for learned patterns, and stay synchronized – without scanning the entire tree.

πŸ€– For AI Agents & Humans

πŸ€– If you're an AI agent: Read the complete setup guide for agents β†’ or πŸ‘€ If you're human: Share the agent setup guide with your AI assistant to automatically configure PAMPA!

πŸ“š Table of Contents

🧠 Semantic Features

🏷️ Automatic Semantic Tagging

PAMPA automatically extracts semantic tags from your code without any special comments:

// File: app/Services/Payment/StripeService.php
function createCheckoutSession() { ... }

Automatic tags: ["stripe", "service", "payment", "checkout", "session", "create"]

🎯 Intention-Based Direct Search

The system learns from successful searches and provides instant responses:

# First search (vector search)
"stripe payment session" β†’ 0.9148 similarity

# System automatically learns and caches this pattern
# Next similar searches are instant:
"create stripe session" β†’ instant response (cached)
"stripe checkout session" β†’ instant response (cached)

πŸ“ˆ Adaptive Learning System

  • Automatic Learning: Saves successful searches (>80% similarity) as intentions
  • Query Normalization: Understands variations: "create" = "crear", "session" = "sesion"
  • Pattern Recognition: Groups similar queries: "[PROVIDER] payment session"

🏷️ Optional @pampa-comments (Complementary)

Enhance search precision with optional JSDoc-style comments:

/**
 * @pampa-tags: stripe-checkout, payment-processing, e-commerce-integration
 * @pampa-intent: create secure stripe checkout session for payments
 * @pampa-description: Main function for handling checkout sessions with validation
 */
async function createStripeCheckoutSession(sessionData) {
	// Your code here...
}

Benefits:

  • +21% better precision when present
  • Perfect scores (1.0) when query matches intent exactly
  • Fully optional: Code without comments works automatically
  • Retrocompatible: Existing codebases work without changes

πŸ“Š Search Performance Results

Search TypeWithout @pampaWith @pampaImprovement
Domain-specific0.73310.8874+21%
Intent matching~0.61.0000+67%
General search0.6-0.80.8-1.0+32-85%

πŸ“ Supported Languages

PAMPA can index and search code in several languages out of the box:

  • JavaScript / TypeScript (.js, .ts, .tsx, .jsx)
  • PHP (.php)
  • Python (.py)
  • Go (.go)
  • Java (.java)

🧠 Embedding Providers

PAMPA supports multiple providers for generating code embeddings:

ProviderCostPrivacyInstallation
Transformers.js🟒 Free🟒 Totalnpm install @xenova/transformers
Ollama🟒 Free🟒 TotalInstall Ollama + npm install ollama
OpenAIπŸ”΄ ~$0.10/1000 functionsπŸ”΄ NoneSet OPENAI_API_KEY
Cohere🟑 ~$0.05/1000 functionsπŸ”΄ NoneSet COHERE_API_KEY + npm install cohere-ai

Recommendation: Use Transformers.js for personal development (free and private) or OpenAI for maximum quality.

πŸ† Performance Analysis

PAMPA v1.12 uses a specialized architecture for semantic code search with measurable results.

πŸ“Š Performance Metrics

Synthetic Benchmark Results:

| Setting    | P@1   | MRR@5 | nDCG@10 |
| ---------- | ----- | ----- | ------- |
| Base       | 0.750 | 0.833 | 0.863   |
| Hybrid     | 0.875 | 0.917 | 0.934   |
| Hybrid+CE  | 1.000 | 0.958 | 0.967   |

🎯 Search Examples

# Search for authentication functions
pampa search "user authentication"
β†’ AuthController::login, UserService::authenticate, etc.

# Search for payment processing
pampa search "payment processing"
β†’ PaymentService::process, CheckoutController::create, etc.

# Search with specific filters
pampa search "database operations" --lang php --path_glob "app/Models/**"
β†’ UserModel::save, OrderModel::find, etc.

πŸ“ˆ Read Full Analysis β†’

πŸš€ Architectural Advantages

  1. Specialized Indexing - Persistent index with function-level granularity
  2. Hybrid Search - BM25 + Vector + Cross-encoder reranking combination
  3. Code Awareness - Symbol boosting, AST analysis, function signatures
  4. Multi-Project - Native support for context across different codebases

Result: Optimized architecture for semantic code search with verifiable metrics.

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ Repo (git) ─────────-──┐
β”‚ app/… src/… package.json etc.      β”‚
β”‚ pampa.codemap.json                 β”‚
β”‚ .pampa/chunks/*.gz(.enc)          β”‚
β”‚ .pampa/pampa.db (SQLite)           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β–²       β–²
          β”‚ write β”‚ read
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚ indexer.js        β”‚   β”‚
β”‚ (pampa index)     β”‚   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β–²β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
          β”‚ store       β”‚ vector query
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚ gz fetch
β”‚ SQLite (local)     β”‚  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β–²β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
          β”‚ read        β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚ mcp-server.js      β”‚β—„β”€β”˜
β”‚ (pampa mcp)        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Components

LayerRoleTechnology
IndexerCuts code into semantic chunks, embeds, writes codemap and SQLitetree-sitter, openai@v4, sqlite3
CodemapGit-friendly JSON with {file, symbol, sha, lang} per chunkPlain JSON
Chunks dir.gz code bodies (or .gz.enc when encrypted) (lazy loading)gzip β†’ AES-256-GCM when enabled
SQLiteStores vectors and metadatasqlite3
MCP ServerExposes tools and resources over standard MCP protocol@modelcontextprotocol/sdk
LoggingDebug and error logging in project directoryFile-based logs

πŸ”§ Available MCP Tools

The MCP server exposes these tools that agents can use:

search_code

Search code semantically in the indexed project.

  • Parameters:
    • query (string) - Semantic search query (e.g., "authentication function", "error handling")
    • limit (number, optional) - Maximum number of results to return (default: 10)
    • provider (string, optional) - Embedding provider (default: "auto")
    • path (string, optional) - PROJECT ROOT directory path where PAMPA database is located
  • Database Location: {path}/.pampa/pampa.db
  • Returns: List of matching code chunks with similarity scores and SHAs

get_code_chunk

Get complete code of a specific chunk.

  • Parameters:
    • sha (string) - SHA of the code chunk to retrieve (obtained from search_code results)
    • path (string, optional) - PROJECT ROOT directory path (same as used in search_code)
  • Chunk Location: {path}/.pampa/chunks/{sha}.gz or {sha}.gz.enc
  • Returns: Complete source code

index_project

Index a project from the agent.

  • Parameters:
    • path (string, optional) - PROJECT ROOT directory path to index (will create .pampa/ subdirectory here)
    • provider (string, optional) - Embedding provider (default: "auto")
  • Creates:
    • {path}/.pampa/pampa.db (SQLite database with embeddings)
    • {path}/.pampa/chunks/ (compressed code chunks)
    • {path}/pampa.codemap.json (lightweight index for version control)
  • Effect: Updates database and codemap

update_project

πŸ”„ CRITICAL: Use this tool frequently to keep your AI memory current!

Update project index after code changes (recommended workflow tool).

  • Parameters:
    • path (string, optional) - PROJECT ROOT directory path to update (same as used in index_project)
    • provider (string, optional) - Embedding provider (default: "auto")
  • Updates:
    • Re-scans all files for changes
    • Updates embeddings for modified functions
    • Removes deleted functions from database
    • Adds new functions to database
  • When to use:
    • βœ… At the start of development sessions
    • βœ… After creating new functions
    • βœ… After modifying existing functions
    • βœ… After deleting functions
    • βœ… Before major code analysis tasks
    • βœ… After refactoring code
  • Effect: Keeps your AI agent's code memory synchronized with current state

get_project_stats

Get indexed project statistics.

  • Parameters:
    • path (string, optional) - PROJECT ROOT directory path where PAMPA database is located
  • Database Location: {path}/.pampa/pampa.db
  • Returns: Statistics by language and file

πŸ“Š Available MCP Resources

pampa://codemap

Access to the complete project code map.

pampa://overview

Summary of the project's main functions.

🎯 Available MCP Prompts

analyze_code

Template for analyzing found code with specific focus.

find_similar_functions

Template for finding existing similar functions.

πŸ” How Retrieval Works

  • Vector search – Cosine similarity with advanced high-dimensional embeddings
  • Summary fallback – If an agent sends an empty query, PAMPA returns top-level summaries so the agent understands the territory
  • Chunk granularity – Default = function/method/class. Adjustable per language

πŸ“ Design Decisions

  • Node only β†’ Devs run everything via npx, no Python, no Docker
  • SQLite over HelixDB β†’ One local database for vectors and relations, no external dependencies
  • Committed codemap β†’ Context travels with repo β†’ cloning works offline
  • Chunk granularity β†’ Default = function/method/class. Adjustable per language
  • Read-only by default β†’ Server only exposes read methods. Writing is done via CLI

🧩 Extending PAMPA

IdeaHint
More languagesInstall tree-sitter grammar and add it to LANG_RULES
Custom embeddingsExport OPENAI_API_KEY or switch OpenAI for any provider that returns vector: number[]
SecurityRun behind a reverse proxy with authentication
VS Code PluginPoint an MCP WebView client to your local server

πŸ” Encrypting the Chunk Store

PAMPA can encrypt chunk bodies at rest using AES-256-GCM. Configure it like this:

  1. Export a 32-byte key in base64 or hex form:

    export PAMPA_ENCRYPTION_KEY="$(openssl rand -base64 32)"
  2. Index with encryption enabled (skips plaintext writes even if stale files exist):

    npx pampa index --encrypt on

    Without --encrypt, PAMPA auto-encrypts when the environment key is present. Use --encrypt off to force plaintext (e.g., for debugging).

  3. All new chunks are stored as .gz.enc and require the same key for CLI or MCP chunk retrieval. Missing or corrupt keys surface clear errors instead of leaking data.

Existing plaintext archives remain readable, so you can enable encryption incrementally or rotate keys by re-indexing.

🀝 Contributing

  1. Fork β†’ create feature branch (feat/...)
  2. Run npm test (coming soon) & npx pampa index before PR
  3. Open PR with context: why + screenshots/logs

All discussions on GitHub Issues.

πŸ“œ License

MIT – do whatever you want, just keep the copyright.

Happy hacking! πŸ’™


πŸ‡¦πŸ‡· Made with ❀️ in Argentina | πŸ‡¦πŸ‡· Hecho con ❀️ en Argentina