Skip to content

Commit

Permalink
docs: Fixed linting and formatting issues
Browse files Browse the repository at this point in the history
Added lint and formatting changes

Docs
  • Loading branch information
dexters1 committed Dec 18, 2024
1 parent b91f4b1 commit 1e6d703
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,4 @@ env/
venv/
ENV/
env.bak/
venv.bak/
venv.bak/
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Cognee assists developers in introducing greater predictability and management i

For more information, visit [Cognee documentation](https://docs.cognee.ai/)


## Installation

```shell
Expand All @@ -21,14 +20,16 @@ import asyncio
from llama_index.core import Document
from llama_index.graph_rag.cognee import CogneeGraphRAG


async def example_graph_rag_cognee():
# Gather documents to add to GraphRAG
news = pd.read_csv(
"https://raw.githubusercontent.com/tomasonjo/blog-datasets/main/news_articles.csv"
)[:5]
news.head()
documents = [
Document(text=f"{row['title']}: {row['text']}") for i, row in news.iterrows()
Document(text=f"{row['title']}: {row['text']}")
for i, row in news.iterrows()
]

# Instantiate cognee GraphRAG
Expand All @@ -42,7 +43,7 @@ async def example_graph_rag_cognee():

# Add data to cognee
await cogneeRAG.add(documents, "test")

# Process data into a knowledge graph
await cogneeRAG.process_data("test")

Expand All @@ -61,4 +62,4 @@ async def example_graph_rag_cognee():

if __name__ == "__main__":
asyncio.run(example_graph_rag_cognee())
```
```
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from llama_index.graph_rag.cognee.graph_rag import CogneeGraphRAG

__all__ = ['CogneeGraphRAG']
__all__ = ["CogneeGraphRAG"]
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
from abc import abstractmethod
from typing import Protocol


# NOTE: This is a bare-bone suggestion for an abstract protocol to define GraphRAG for llama-index
# This should be expanded upon and integrated to llama-index-core to support multiple different GraphRAG
# libraries in the future
class GraphRAG(Protocol):
"""Abstract graph RAG protocol.
This protocol defines the interface for a graphRAG, which is responsible
for adding, storing, processing and retrieving information from knowledge graphs.
This protocol defines the interface for a graphRAG, which is responsible
for adding, storing, processing and retrieving information from knowledge graphs.
Attributes:
llm_api_key: str: Api key for desired llm.
graph_db_provider: str: The graph database provider.
vector_db_provider: str: The vector database provider.
relational_db_provider: str: The relational database provider.
db_name: str: The name of the databases.
"""

Attributes:
llm_api_key: str: Api key for desired llm.
graph_db_provider: str: The graph database provider.
vector_db_provider: str: The vector database provider.
relational_db_provider: str: The relational database provider.
db_name: str: The name of the databases.
"""
@abstractmethod
async def add(self, data, dataset_name):
"""Add data to the specified dataset.
This data will later be processed and made into a knowledge graph.
Args:
Args:
data (Any): The data to be added to the graph.
dataset_name (str): Name of the dataset or node set where the data will be added.
"""
pass

@abstractmethod
async def process_data(self, dataset_name: str):
Expand All @@ -35,7 +36,6 @@ async def process_data(self, dataset_name: str):
Args:
dataset_name (str): The dataset name to process.
"""
pass

@abstractmethod
async def search(self, query: str):
Expand All @@ -44,7 +44,6 @@ async def search(self, query: str):
Args:
query (str): The query string to match against data from the graph.
"""
pass

@abstractmethod
async def get_related_nodes(self, node_id: str):
Expand All @@ -53,4 +52,3 @@ async def get_related_nodes(self, node_id: str):
Args:
node_id (str): The name of the node to match against nodes in the graph.
"""
pass
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,25 @@
import pathlib
from typing import List

from cognee.modules.users.methods import get_default_user
from cognee.modules.data.methods import get_datasets_by_name
from cognee.api.v1.search import SearchType
import cognee

from llama_index.core import Document

from .base import GraphRAG


class CogneeGraphRAG(GraphRAG):
def __init__(
self,
llm_api_key,
graph_db_provider,
vector_db_provider,
relational_db_provider,
db_name
):

db_name,
) -> None:
cognee.config.set_llm_config({"llm_api_key": llm_api_key})

cognee.config.set_vector_db_config(
{"vector_db_provider": vector_db_provider}
)
cognee.config.set_vector_db_config({"vector_db_provider": vector_db_provider})
cognee.config.set_relational_db_config(
{"db_provider": relational_db_provider, "db_name": db_name}
)
Expand All @@ -49,7 +44,7 @@ async def add(self, data, dataset_name: str):
"""Add data to the specified dataset.
This data will later be processed and made into a knowledge graph.
Args:
Args:
data (Any): The data to be added to the graph.
dataset_name (str): Name of the dataset or node set where the data will be added.
"""
Expand All @@ -68,7 +63,9 @@ async def process_data(self, dataset_names: str):
dataset_name (str): The dataset name to process.
"""
user = await cognee.modules.users.methods.get_default_user()
datasets = await cognee.modules.data.methods.get_datasets_by_name(dataset_names, user.id)
datasets = await cognee.modules.data.methods.get_datasets_by_name(
dataset_names, user.id
)
await cognee.cognify(datasets, user)

async def get_graph_url(self, graphistry_password, graphistry_username) -> str:
Expand Down Expand Up @@ -103,7 +100,9 @@ async def search(self, query: str):
query (str): The query string to match against data from the graph.
"""
user = await cognee.modules.users.methods.get_default_user()
return await cognee.search(cognee.api.v1.search.SearchType.SUMMARIES, query, user)
return await cognee.search(
cognee.api.v1.search.SearchType.SUMMARIES, query, user
)

async def get_related_nodes(self, node_id: str):
"""Search the graph for relevant nodes or relationships based on node id.
Expand All @@ -112,4 +111,6 @@ async def get_related_nodes(self, node_id: str):
node_id (str): The name of the node to match against nodes in the graph.
"""
user = await cognee.modules.users.methods.get_default_user()
return await cognee.search(cognee.api.v1.search.SearchType.INSIGHTS, node_id, user)
return await cognee.search(
cognee.api.v1.search.SearchType.INSIGHTS, node_id, user
)
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ async def test_graph_rag_cognee():


if __name__ == "__main__":
asyncio.run(test_graph_rag_cognee())
asyncio.run(test_graph_rag_cognee())

0 comments on commit 1e6d703

Please sign in to comment.