File size: 516 Bytes
3f091a9
 
 
 
 
 
 
 
 
d947206
 
3f091a9
d947206
3f091a9
 
 
 
d947206
3f091a9
 
 
 
 
 
 
 
 
 
 
d947206
3f091a9
 
 
d947206
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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]