Skip to main content
Glama
Alpha-Park

genpark-context-window-lost-in-middle-reorderer-skill

by Alpha-Park
README.md
# genpark-context-window-lost-in-middle-reorderer-skill

<div align="center">

[![Python 3.9+](https://img.shields.io/badge/python-3.9%2B-blue.svg?style=for-the-badge&logo=python)](https://www.python.org/)
[![License MIT](https://img.shields.io/badge/license-MIT-green.svg?style=for-the-badge)](LICENSE)
[![MCP Compatible](https://img.shields.io/badge/MCP-100%25%20Compatible-purple.svg?style=for-the-badge&logo=anthropic)](https://genpark.ai/mcp)
[![GenPark AI](https://img.shields.io/badge/Verified%20By-GenPark%20AI-orange.svg?style=for-the-badge&logo=openai)](https://genpark.ai)
[![Zero Dependencies](https://img.shields.io/badge/Dependencies-0%20(Stdlib%20Only)-brightgreen.svg?style=for-the-badge)](requirements.txt)

<p align="center">
  <b>Production-Grade Agentic Memory, Vector Search & Graph RAG Skill</b> • <b>100% Standard Library Python</b> • <b>Native Model Context Protocol (MCP)</b>
</p>

</div>

---

## ⚡ Overview & Architectural Significance

`genpark-context-window-lost-in-middle-reorderer-skill` delivers zero-dependency, low-latency, deterministic agentic memory and retrieval primitives engineered strictly using Python 3.9+ standard library.

### 🌟 Key Architectural Capabilities
- **Zero External Dependencies**: Operates exclusively via pure Python (`math`, `re`, `collections`, `heapq`, `hashlib`, `json`). Zero pip install overhead, zero C-extension compile errors.
- **Enterprise RAG & Memory Invariants**: Implements formal algorithms for cognitive decay, BM25 Okapi lexical scoring, Reciprocal Rank Fusion, knowledge graph traversal, semantic query caching, and lost-in-the-middle context reordering.
- **Native Anthropic MCP Protocol**: Compliant with standard JSON-RPC 2.0 stdio MCP specifications for Claude Desktop, Cursor, and Windsurf.

---

## 🏗️ Architectural Topology & State Machine

```mermaid
flowchart TD
    UserQuery["User Prompt / Agent Goal"] --> SemCache["Semantic Cache Check"]
    SemCache -->|Cache Hit| FastReturn["Cached Response (0ms)"]
    SemCache -->|Cache Miss| DualRetrieval["Dual Retrieval Pipeline"]
    
    subgraph DualRetrieval ["Hybrid Search Engine"]
        BM25Lex["BM25 Okapi Lexical Ranker"]
        DenseVec["Dense Cosine Vector Similarity"]
    end
    
    DualRetrieval --> RRF["Reciprocal Rank Fusion (RRF)"]
    RRF --> GraphExp["Knowledge Graph Triplet Expansion"]
    GraphExp --> LostMiddle["Lost-In-The-Middle Context Reorderer"]
    LostMiddle --> LLM["LLM Synthesis with Optimal Context"]
    LLM --> EpisodicMem["Episodic Consolidation & Recency Decay"]
```

---

## 🚀 Quickstart & Standalone Execution

### Local Python Client Usage

```python
from client import ContextWindowLostInMiddleReorderer

# Initialize engine
engine = ContextWindowLostInMiddleReorderer()

# Execute self-testing benchmark suite
result = engine.run_benchmark_reorderer()
print("Execution Result:", result)
```

---

## 🔌 One-Click MCP Integration (Claude Desktop / Cursor)

Add to your `claude_desktop_config.json` or `cursor.json`:

```json
{
  "mcpServers": {
    "genpark-context-window-lost-in-middle-reorderer-skill": {
      "command": "python",
      "args": ["-u", "/path/to/genpark-context-window-lost-in-middle-reorderer-skill/mcp_server.py"]
    }
  }
}
```

---

## 📦 Smithery.ai & PyPI Deployment

This skill contains pre-configured `smithery.yaml` and `pyproject.toml` manifests. Install directly via pip:

```bash
pip install git+https://github.com/alphaparkinc/genpark-context-window-lost-in-middle-reorderer-skill.git
```

---

<div align="center">
  <sub>Maintained with ❤️ by <b><a href="https://genpark.ai">GenPark AI Engineering</a></b> • Powering Next-Gen Autonomous Cognitive Agents 🌍</sub>
</div>