Spaces:
Build error
Build error
| import networkx as nx | |
| from vector_store import search | |
| GRAPH = nx.Graph() | |
| def build_graph(docs): | |
| for i in range(len(docs)-1): | |
| GRAPH.add_node(docs[i]) | |
| GRAPH.add_node(docs[i+1]) | |
| GRAPH.add_edge(docs[i], docs[i+1]) | |
| def hyperrag(query): | |
| hits = search(query) | |
| context = [] | |
| for h in hits: | |
| text = h["text"] | |
| context.append(text) | |
| if text in GRAPH: | |
| for n in GRAPH.neighbors(text): | |
| context.append(n) | |
| return context[:5] |