Neo4j rag
Neo4jRAG
Source code in Docs2KG/rag/neo4j_rag.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 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 |
|
__init__(uri, user, password)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri |
str
|
uri of the graph database |
required |
user |
str
|
username of the graph database |
required |
password |
str
|
password of the graph database |
required |
Source code in Docs2KG/rag/neo4j_rag.py
15 16 17 18 19 20 21 22 23 |
|
cosine_similarity(embedding1, embedding2)
staticmethod
Calculate the cosine similarity between two embeddings
Parameters:
Name | Type | Description | Default |
---|---|---|---|
embedding1 |
list
|
embedding 1 |
required |
embedding2 |
list
|
embedding 2 |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
similarity score |
Source code in Docs2KG/rag/neo4j_rag.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
|
retrieval(query, top_k=10)
Retrieve the best matching node from the graph based on the query
We choose to use our way to do the similarity calculation, which will be slow
However, it is just a demonstration about how should you do it. Args: query (str): query string top_k (int): number of results to return
Returns:
Source code in Docs2KG/rag/neo4j_rag.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
retrieval_strategy_hops_away(uuids, hops=1)
Match all nodes and relationships that are hops
away from the given uuids
the node will have a property uuid
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uuids |
List[str]
|
list of uuids |
required |
hops |
int
|
number of hops away |
1
|
Returns:
Source code in Docs2KG/rag/neo4j_rag.py
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 |
|