Cognee
CogneeGraphRAG #
Cognee GraphRAG, handles adding, storing, processing and retrieving information from knowledge graphs.
Unlike traditional RAG models that retrieve unstructured text snippets, graphRAG utilizes knowledge graphs. A knowledge graph represents entities as nodes and their relationships as edges, often in a structured semantic format. This enables the system to retrieve more precise and structured information about an entity, its relationships, and its properties.
Attributes: llm_api_key: str: API key for desired LLM. llm_provider: str: Provider for desired LLM (default: "openai"). llm_model: str: Model for desired LLM (default: "gpt-4o-mini"). graph_db_provider: str: The graph database provider (default: "kuzu"). Supported providers: "neo4j", "networkx", "kuzu". graph_database_url: str: URL for the graph database. graph_database_username: str: Username for accessing the graph database. graph_database_password: str: Password for accessing the graph database. vector_db_provider: str: The vector database provider (default: "lancedb"). Supported providers: "lancedb", "pgvector", "qdrant", "weviate". vector_db_url: str: URL for the vector database. vector_db_key: str: API key for accessing the vector database. relational_db_provider: str: The relational database provider (default: "sqlite"). Supported providers: "sqlite", "postgres". db_name: str: The name of the databases (default: "cognee_db"). db_host: str: Host for the relational database. db_port: str: Port for the relational database. db_username: str: Username for the relational database. db_password: str: Password for the relational database.
Source code in llama_index/graph_rag/cognee/graph_rag.py
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 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | |
add
async
#
Add data to the specified dataset. This data will later be processed and made into a knowledge graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Union[Document, List[Document]]
|
The document(s) to be added to the graph. Can be a single Document or a list of Documents. |
required |
dataset_name
|
str
|
Name of the dataset or node set where the data will be added. Note: While cognee supports custom dataset organization, this integration currently adds all data to 'main_dataset'. Full dataset_name support will be added in a future version. This parameter is included to show the intended API design. |
'main_dataset'
|
Source code in llama_index/graph_rag/cognee/graph_rag.py
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 | |
process_data
async
#
process_data(dataset_name: str = 'main_dataset') -> None
Process and structure data in the dataset and create a knowledge graph from it.
This method takes the raw data that was previously added and transforms it into a structured knowledge graph with entities, relationships, and properties.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_names
|
str
|
The name of the dataset to process into a knowledge graph. Note: While cognee supports multiple datasets, this integration currently processes 'main_dataset' only. Full dataset_names support will be added in a future version. This parameter is included to show the intended API design. |
required |
Source code in llama_index/graph_rag/cognee/graph_rag.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
rag_search
async
#
rag_search(query: str) -> list
Answer query using traditional RAG approach with document chunks.
This method performs retrieval-augmented generation by finding the most relevant document chunks and generating a response based on them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
The question or query to answer. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
Search results containing relevant document chunks and generated responses. |
Source code in llama_index/graph_rag/cognee/graph_rag.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
search
async
#
search(query: str) -> list
Search the knowledge graph for relevant information using graph-based retrieval.
This method leverages the graph structure to find related entities, relationships, and contextual information that traditional RAG might miss.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
The question or search term to match against entities and relationships in the graph. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
Search results containing graph-based insights and related information. |
Source code in llama_index/graph_rag/cognee/graph_rag.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
get_related_nodes
async
#
get_related_nodes(node_id: str) -> list
Find nodes and relationships connected to a specific node in the knowledge graph.
This method explores the graph structure to discover entities and concepts that are directly or indirectly related to the specified node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id
|
str
|
The identifier or name of the node to find connections for. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
Related nodes, relationships, and insights connected to the specified node. |
Source code in llama_index/graph_rag/cognee/graph_rag.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
visualize_graph
async
#
visualize_graph(open_browser: bool = False, output_file_path: str | None = None) -> str
Generate HTML visualization of the graph and optionally open in browser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
open_browser
|
bool
|
Whether to automatically open the visualization in the default browser. Defaults to False. |
False
|
output_file_path
|
str | None
|
Directory path where the HTML file will be saved. If None, saves to user's home directory. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Full path to the generated HTML visualization file. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If output_file_path is provided but is not a valid directory. |
Source code in llama_index/graph_rag/cognee/graph_rag.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | |
options: members: - GraphRag