How to Build an Elastic Vector Database with Consistent Hashing, Sharding, and Live Ring Visualization for RAG Systems

How to Build an Elastic Vector Database with Consistent Hashing, Sharding, and Live Ring Visualization for RAG Systems


def draw_ring(ring: ConsistentHashRing, dist: Dict[str, int], title: str):
node_ids = sorted(ring.nodes.keys())
plt.figure(figsize=(8, 8))
ax = plt.gca()
ax.set_title(title)

if not node_ids:
plt.text(0.5, 0.5, “Ring is empty”, ha=”center”, va=”center”)
plt.axis(“off”)
plt.show()
return

G = nx.Graph()
for nid in node_ids:
G.add_node(nid)
for i in range(len(node_ids)):
G.add_edge(node_ids[i], node_ids[(i + 1) % len(node_ids)])

pos = nx.circular_layout(G)
vnode_counts = ring.snapshot()
labels = {
nid: f”{nid}\nkeys={dist.get(nid,0)}\nvnodes={vnode_counts.get(nid,0)}”
for nid in node_ids
}

nx.draw_networkx_edges(G, pos, alpha=0.4, width=2)
nx.draw_networkx_nodes(G, pos, node_size=2200)
nx.draw_networkx_labels(G, pos, labels=labels, font_size=9)
plt.axis(“off”)
plt.show()



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest