Geometrical vector reranking algorithm in Python & NumPy for fast RAG context filtering without external APIs.
A Python and NumPy implementation of a dynamic subspace clustering algorithm used for RAG context reranking.
Instead of relying on heavy third-party cross-encoder reranking APIs, this function uses local centroid shifting and contrastive geometry to filter vector search results directly in memory.
Key features:
Centroid-Based Origin Shift: Shifts query and document embeddings relative to their local cluster mean.
Iterative Subspace Zoom: Filters low-contrast embeddings across up to 5 dynamic refinement cycles.
In-Memory Performance: Runs using vector operations in NumPy without network latency or external API costs.
Data Validation: Handles zero-vectors and invalid dimension shapes gracefully during retrieval.