base
ipw.agents.mcp.retrieval.base
¶
Base classes for retrieval MCP servers.
All retrieval servers inherit from BaseRetrievalServer, which extends BaseMCPServer to provide automatic telemetry capture for energy, power, and latency.
Document
dataclass
¶
A document for retrieval indexing.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique document identifier |
content |
str
|
Document text content |
metadata |
Dict[str, Any]
|
Optional metadata (e.g., title, source, date) |
Source code in intelligence-per-watt/src/ipw/agents/mcp/retrieval/base.py
__post_init__()
¶
RetrievalResult
dataclass
¶
A single retrieval result with score.
Attributes:
| Name | Type | Description |
|---|---|---|
document |
Document
|
The retrieved document |
score |
float
|
Relevance score (higher is better) |
highlights |
List[str]
|
Optional highlighted text snippets |
Source code in intelligence-per-watt/src/ipw/agents/mcp/retrieval/base.py
to_dict()
¶
Convert to dictionary for serialization.
Source code in intelligence-per-watt/src/ipw/agents/mcp/retrieval/base.py
BaseRetrievalServer
¶
Bases: BaseMCPServer
Base class for retrieval servers with automatic telemetry.
Subclasses must implement: - _execute_impl(): Perform the actual retrieval - index_documents(): Index a list of documents - clear_index(): Clear all indexed documents
Source code in intelligence-per-watt/src/ipw/agents/mcp/retrieval/base.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
document_count
property
¶
Get the number of indexed documents.
__init__(name, telemetry_collector=None, event_recorder=None)
¶
Initialize retrieval server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Server name (e.g., "retrieval:bm25") |
required |
telemetry_collector
|
Optional[Any]
|
Energy monitor collector for telemetry |
None
|
event_recorder
|
Optional[Any]
|
EventRecorder for per-action tracking |
None
|
Source code in intelligence-per-watt/src/ipw/agents/mcp/retrieval/base.py
index_documents(documents)
abstractmethod
¶
Index a list of documents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
documents
|
List[Document]
|
List of documents to index |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of documents successfully indexed |