MCPcopy Create free account
hub / github.com/apache/burr / _socket_name_mapping

Function _socket_name_mapping

burr/integrations/haystack.py:291–318  ·  view source on GitHub ↗

Map socket names to a single socket name. In Haystack, components communicate via sockets. A socket called "embedding" in one component can be renamed to "query_embedding" when passed to another component. In Burr, there is a single state object so we need a mapping to resolve

(sockets_connections: list[tuple[str, str]])

Source from the content-addressed store, hash-verified

289
290
291def _socket_name_mapping(sockets_connections: list[tuple[str, str]]) -> dict[str, str]:
292 """Map socket names to a single socket name.
293
294 In Haystack, components communicate via sockets. A socket called
295 "embedding" in one component can be renamed to "query_embedding" when
296 passed to another component.
297
298 In Burr, there is a single state object so we need a mapping to resolve
299 that `embedding` and `query_embedding` point to the same value. This function
300 creates a mapping {socket_name: state_field} to rename sockets when creating
301 the Burr `Graph`.
302 """
303 all_connections: dict[str, set[str]] = {}
304 for from_, to in sockets_connections:
305 if from_ not in all_connections:
306 all_connections[from_] = {from_}
307 all_connections[from_].add(to)
308
309 if to not in all_connections:
310 all_connections[to] = {to}
311 all_connections[to].add(from_)
312
313 reduced_mapping: dict[str, str] = {}
314 for key, values in all_connections.items():
315 unique_name = min(values)
316 reduced_mapping[key] = unique_name
317
318 return reduced_mapping
319
320
321def _connected_inputs(pipeline) -> dict[str, list[str]]:

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected