Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /ViperJuice_Code-Index-MCP /mcp_server /interfaces /indexing_interfaces.py
| """ | |
| Indexing Engine Interfaces | |
| All interfaces related to code indexing, search optimization, and semantic analysis. | |
| """ | |
| from abc import ABC, abstractmethod | |
| from dataclasses import dataclass | |
| from datetime import datetime | |
| from typing import Any, Dict, List, Optional, Set | |
| from .plugin_interfaces import ( | |
| IndexedFile, | |
| SearchResult, | |
| SymbolDefinition, | |
| SymbolReference, | |
| ) | |
| from .shared_interfaces import IAsyncRepository, IndexStatus, IObservable, Result | |
| # ======================================== | |
| # Indexing Data Types | |
| # ======================================== | |
| class IndexEntry: | |
| """Single index entry""" | |
| file_path: str | |
| symbol: str | |
| symbol_type: str | |
| line: int | |
| column: int | |
| content_hash: str | |
| last_indexed: datetime | |
| metadata: Dict[str, Any] = None | |
| class IndexStatistics: | |
| """Index statistics""" | |
| total_files: int | |
| total_symbols: int | |
| index_size_bytes: int | |
| last_update: datetime | |
| index_health: str | |
| plugin_stats: Dict[str, Dict[str, int]] | |
| class SearchQuery: | |
| """Search query with options""" | |
| query: str | |
| search_type: str # exact, fuzzy, semantic, regex | |
| file_patterns: List[str] = None | |
| language_filters: List[str] = None | |
| symbol_types: List[str] = None | |
| max_results: int = 100 | |
| include_context: bool = True | |
| case_sensitive: bool = False | |
| class IndexingTask: | |
| """Task for indexing operations""" | |
| task_id: str | |
| file_path: str | |
| operation: str # index, reindex, delete | |
| priority: int | |
| created_at: datetime | |
| status: IndexStatus | |
| progress: float = 0.0 | |
| error_message: Optional[str] = None | |
| class SemanticMatch: | |
| """Semantic search match""" | |
| symbol: str | |
| file_path: str | |
| similarity_score: float | |
| embedding_vector: List[float] | |
| context: str | |
| metadata: Dict[str, Any] = None | |
| # ======================================== | |
| # Core Indexing Interfaces | |
| # ======================================== | |
| class IIndexEngine(IObservable): | |
| """Main interface for the indexing engine""" | |
| async def initialize(self, config: Dict[str, Any]) -> Result[None]: | |
| """Initialize the indexing engine""" | |
| async def shutdown(self) -> Result[None]: | |
| """Shutdown the indexing engine""" | |
| async def index_file(self, file_path: str, force: bool = False) -> Result[IndexedFile]: | |
| """Index a single file""" | |
| async def index_directory( | |
| self, directory: str, recursive: bool = True | |
| ) -> Result[List[IndexedFile]]: | |
| """Index all files in a directory""" | |
| async def reindex_file(self, file_path: str) -> Result[IndexedFile]: | |
| """Reindex a specific file""" | |
| async def remove_file(self, file_path: str) -> Result[None]: | |
| """Remove a file from the index""" | |
| async def search(self, query: SearchQuery) -> Result[List[SearchResult]]: | |
| """Search the index""" | |
| async def get_statistics(self) -> Result[IndexStatistics]: | |
| """Get index statistics""" | |
| class IIndexCoordinator(ABC): | |
| """Interface for coordinating indexing operations across plugins""" | |
| async def coordinate_indexing(self, files: List[str]) -> Result[Dict[str, IndexedFile]]: | |
| """Coordinate indexing across multiple plugins""" | |
| async def schedule_indexing_task(self, task: IndexingTask) -> Result[str]: | |
| """Schedule an indexing task""" | |
| async def get_indexing_status(self, task_id: str) -> Result[IndexingTask]: | |
| """Get status of an indexing task""" | |
| async def cancel_indexing_task(self, task_id: str) -> Result[None]: | |
| """Cancel an indexing task""" | |
| async def get_pending_tasks(self) -> Result[List[IndexingTask]]: | |
| """Get list of pending indexing tasks""" | |
| class IParseCoordinator(ABC): | |
| """Interface for coordinating parsing operations""" | |
| async def parse_file( | |
| self, file_path: str, content: Optional[str] = None | |
| ) -> Result[List[SymbolDefinition]]: | |
| """Parse a file using appropriate plugins""" | |
| async def parse_content(self, content: str, language: str) -> Result[List[SymbolDefinition]]: | |
| """Parse content for a specific language""" | |
| async def batch_parse(self, files: List[str]) -> Result[Dict[str, List[SymbolDefinition]]]: | |
| """Parse multiple files in batch""" | |
| def get_supported_languages(self) -> List[str]: | |
| """Get list of supported languages""" | |
| # ======================================== | |
| # Search Interfaces | |
| # ======================================== | |
| class ISearchEngine(ABC): | |
| """Interface for search operations""" | |
| async def search_symbols( | |
| self, query: str, options: Dict[str, Any] | |
| ) -> Result[List[SymbolDefinition]]: | |
| """Search for symbols""" | |
| async def search_references( | |
| self, symbol: str, options: Dict[str, Any] | |
| ) -> Result[List[SymbolReference]]: | |
| """Search for symbol references""" | |
| async def search_content( | |
| self, query: str, options: Dict[str, Any] | |
| ) -> Result[List[SearchResult]]: | |
| """Search file content""" | |
| async def search_fuzzy(self, query: str, options: Dict[str, Any]) -> Result[List[SearchResult]]: | |
| """Perform fuzzy search""" | |
| async def search_semantic( | |
| self, query: str, options: Dict[str, Any] | |
| ) -> Result[List[SemanticMatch]]: | |
| """Perform semantic search""" | |
| class IQueryOptimizer(ABC): | |
| """Interface for optimizing search queries""" | |
| def optimize_query(self, query: SearchQuery) -> SearchQuery: | |
| """Optimize a search query""" | |
| def estimate_cost(self, query: SearchQuery) -> float: | |
| """Estimate the cost of executing a query""" | |
| def suggest_improvements(self, query: SearchQuery) -> List[str]: | |
| """Suggest query improvements""" | |
| def get_query_plan(self, query: SearchQuery) -> Dict[str, Any]: | |
| """Get execution plan for a query""" | |
| class ISearchPlanner(ABC): | |
| """Interface for planning search execution""" | |
| def create_execution_plan(self, query: SearchQuery) -> Dict[str, Any]: | |
| """Create an execution plan for a search query""" | |
| def select_indexes(self, query: SearchQuery) -> List[str]: | |
| """Select appropriate indexes for a query""" | |
| def estimate_selectivity(self, query: SearchQuery) -> float: | |
| """Estimate query selectivity""" | |
| # ======================================== | |
| # Indexing Strategy Interfaces | |
| # ======================================== | |
| class IFuzzyIndexer(ABC): | |
| """Interface for fuzzy text indexing""" | |
| async def build_fuzzy_index(self, content: str, file_path: str) -> Result[None]: | |
| """Build fuzzy index for content""" | |
| async def search_fuzzy(self, query: str, max_distance: int = 2) -> Result[List[SearchResult]]: | |
| """Search with fuzzy matching""" | |
| async def get_suggestions(self, partial_query: str, limit: int = 10) -> Result[List[str]]: | |
| """Get search suggestions""" | |
| def calculate_similarity(self, text1: str, text2: str) -> float: | |
| """Calculate similarity between two texts""" | |
| class ISemanticIndexer(ABC): | |
| """Interface for semantic indexing with embeddings""" | |
| async def generate_embeddings( | |
| self, content: str, metadata: Dict[str, Any] = None | |
| ) -> Result[List[float]]: | |
| """Generate embeddings for content""" | |
| async def index_embeddings( | |
| self, embeddings: List[float], content: str, file_path: str | |
| ) -> Result[None]: | |
| """Index embeddings""" | |
| async def search_similar( | |
| self, query_embedding: List[float], top_k: int = 10 | |
| ) -> Result[List[SemanticMatch]]: | |
| """Search for similar content using embeddings""" | |
| async def update_embeddings(self, file_path: str, content: str) -> Result[None]: | |
| """Update embeddings for a file""" | |
| class ITrigramSearcher(ABC): | |
| """Interface for trigram-based search""" | |
| async def build_trigram_index(self, content: str, file_path: str) -> Result[None]: | |
| """Build trigram index""" | |
| async def search_trigrams(self, query: str) -> Result[List[SearchResult]]: | |
| """Search using trigrams""" | |
| def extract_trigrams(self, text: str) -> Set[str]: | |
| """Extract trigrams from text""" | |
| # ======================================== | |
| # Index Management Interfaces | |
| # ======================================== | |
| class IIndexManager(ABC): | |
| """Interface for managing indexes""" | |
| async def create_index( | |
| self, index_name: str, index_type: str, config: Dict[str, Any] | |
| ) -> Result[None]: | |
| """Create a new index""" | |
| async def drop_index(self, index_name: str) -> Result[None]: | |
| """Drop an index""" | |
| async def rebuild_index(self, index_name: str) -> Result[None]: | |
| """Rebuild an index""" | |
| async def optimize_index(self, index_name: str) -> Result[None]: | |
| """Optimize an index""" | |
| async def get_index_info(self, index_name: str) -> Result[Dict[str, Any]]: | |
| """Get information about an index""" | |
| async def list_indexes(self) -> Result[List[str]]: | |
| """List all indexes""" | |
| class IIndexStore(IAsyncRepository[IndexEntry]): | |
| """Interface for storing index data""" | |
| async def store_symbols(self, file_path: str, symbols: List[SymbolDefinition]) -> Result[None]: | |
| """Store symbols for a file""" | |
| async def get_symbols(self, file_path: str) -> Result[List[SymbolDefinition]]: | |
| """Get symbols for a file""" | |
| async def delete_symbols(self, file_path: str) -> Result[None]: | |
| """Delete symbols for a file""" | |
| async def search_symbols( | |
| self, query: str, filters: Dict[str, Any] | |
| ) -> Result[List[SymbolDefinition]]: | |
| """Search symbols with filters""" | |
| # ======================================== | |
| # Change Detection Interfaces | |
| # ======================================== | |
| class IChangeDetector(ABC): | |
| """Interface for detecting file changes""" | |
| async def detect_changes(self, file_path: str) -> Result[bool]: | |
| """Detect if a file has changed since last index""" | |
| async def get_file_hash(self, file_path: str) -> Result[str]: | |
| """Get hash of a file""" | |
| async def store_file_hash(self, file_path: str, hash_value: str) -> Result[None]: | |
| """Store file hash""" | |
| async def get_modified_files(self, since: datetime) -> Result[List[str]]: | |
| """Get files modified since a timestamp""" | |
| class IIncrementalIndexer(ABC): | |
| """Interface for incremental indexing""" | |
| async def process_file_change(self, file_path: str, change_type: str) -> Result[None]: | |
| """Process a file change (created, modified, deleted)""" | |
| async def get_incremental_updates(self, since: datetime) -> Result[List[IndexEntry]]: | |
| """Get incremental updates since a timestamp""" | |
| async def apply_incremental_update(self, update: IndexEntry) -> Result[None]: | |
| """Apply an incremental update""" | |
| # ======================================== | |
| # Reranking Interfaces | |
| # ======================================== | |
| # | |
| # CONSOLIDATED (RERANKEND / IF-0-RERANKEND-1): there is now exactly ONE canonical | |
| # reranker interface, the async ``IReranker`` defined in | |
| # ``mcp_server.indexer.reranker``. This module previously declared a DUPLICATE | |
| # ``IReranker`` / ``RerankResult`` / ``IRerankerFactory`` here; those are now | |
| # re-exported from the canonical module so this remains a valid import site for | |
| # existing callers while pointing at a single source of truth. Prefer importing | |
| # these directly from ``mcp_server.indexer.reranker`` in new code. | |
| # | |
| # ``RerankResult`` here now refers to the canonical container | |
| # (``{results: List[RerankItem], metadata: dict}``); the per-item shape is | |
| # ``RerankItem`` (also re-exported). The de-facto return convention is | |
| # ``Result[RerankResult]`` — see the reranker module docstring. | |
| from mcp_server.indexer.reranker import ( # noqa: E402,F401 (re-export for consolidation) | |
| IReranker, | |
| IRerankerFactory, | |
| RerankItem, | |
| RerankResult, | |
| ) | |
| # ======================================== | |
| # Performance Monitoring Interfaces | |
| # ======================================== | |
| class IIndexPerformanceMonitor(ABC): | |
| """Interface for monitoring index performance""" | |
| async def record_indexing_time(self, file_path: str, time_taken: float) -> None: | |
| """Record time taken to index a file""" | |
| async def record_search_time(self, query: str, time_taken: float, result_count: int) -> None: | |
| """Record search performance""" | |
| async def get_performance_metrics(self) -> Result[Dict[str, Any]]: | |
| """Get performance metrics""" | |
| async def get_slow_queries(self, threshold: float) -> Result[List[Dict[str, Any]]]: | |
| """Get queries that took longer than threshold""" | |
| class IBenchmarkRunner(ABC): | |
| """Interface for running performance benchmarks""" | |
| async def run_indexing_benchmark(self, file_paths: List[str]) -> Result[Dict[str, Any]]: | |
| """Run indexing performance benchmark""" | |
| async def run_search_benchmark(self, queries: List[str]) -> Result[Dict[str, Any]]: | |
| """Run search performance benchmark""" | |
| async def run_memory_benchmark(self, file_count: int) -> Result[Dict[str, Any]]: | |
| """Run memory usage benchmark""" | |
| async def generate_benchmark_report(self) -> Result[str]: | |
| """Generate benchmark report""" | |
Xet Storage Details
- Size:
- 14.5 kB
- Xet hash:
- f980737ac7bf689896cfb4b4d4e7af82faf86cd33451fee4805b29f64d64c05f
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.