Skip to content

Commit

Permalink
Shiny new LLMOps
Browse files Browse the repository at this point in the history
  • Loading branch information
Vasilije1990 committed Jun 15, 2024
1 parent 79d299e commit 16139f7
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
27 changes: 26 additions & 1 deletion cognee/api/v1/cognify/cognify.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import os
from uuid import uuid4
from typing import List, Union
import logging
Expand Down Expand Up @@ -149,15 +150,23 @@ async def process_batch(files_batch):
graph_config = get_graph_config()
graph_topology = graph_config.graph_model

print(graph_config.infer_graph_topology)
print(graph_config.graph_topology_task)



if graph_config.infer_graph_topology and graph_config.graph_topology_task:
from cognee.modules.topology.topology import TopologyEngine
topology_engine = TopologyEngine(infer=graph_config.infer_graph_topology)
await topology_engine.add_graph_topology(dataset_files=dataset_files)
print('infered topology added')
parent_node_id=None
elif not graph_config.infer_graph_topology:
from cognee.modules.topology.topology import TopologyEngine
topology_engine = TopologyEngine(infer=graph_config.infer_graph_topology)
await topology_engine.add_graph_topology(graph_config.topology_file_path)
print('provided topology added')
parent_node_id=None
elif not graph_config.graph_topology_task:
parent_node_id = f"DefaultGraphModel__{USER_ID}"

Expand Down Expand Up @@ -294,14 +303,30 @@ async def test():

from cognee.api.v1.add import add

dataset_name = "explanations"
print(os.getcwd())
data_dir = os.path.abspath("../../../.data")
print(os.getcwd())
from pathlib import Path
dir = Path.joinpath(Path.cwd(), ".data")

await add(f"data://{dir}", dataset_name="explanations")

await add([text], "example_dataset")

from cognee.api.v1.config.config import config
config.set_chunk_engine(ChunkEngine.LANGCHAIN_ENGINE )
config.set_chunk_strategy(ChunkStrategy.LANGCHAIN_CHARACTER)
config.embedding_engine = LiteLLMEmbeddingEngine()
config.set_chunk_engine(ChunkEngine.LANGCHAIN_ENGINE)
config.set_graph_topology_task=True
config.set_infer_graph_topology=True

from cognee.api.v1.datasets.datasets import datasets
print(datasets.list_datasets())

graph = await cognify("explanations")

graph = await cognify()
# vector_client = infrastructure_config.get_config("vector_engine")
#
# out = await vector_client.search(collection_name ="basic_rag", query_text="show_all_processes", limit=10)
Expand Down
13 changes: 13 additions & 0 deletions cognee/api/v1/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,18 @@ def set_graphistry_password(graphistry_password: str):
base_config = get_base_config()
base_config.graphistry_password = graphistry_password

@staticmethod
def set_graph_topology_task(graph_topology_task: bool):
base_config = get_graph_config()
base_config.graph_topology_task = graph_topology_task

@staticmethod
def set_infer_graph_topology(infer_graph_topology: bool):
base_config = get_graph_config()
base_config.infer_graph_topology = infer_graph_topology


@staticmethod
def set_topology_file_path(topology_file_path: bool):
base_config = get_graph_config()
base_config.topology_file_path = topology_file_path
5 changes: 3 additions & 2 deletions cognee/infrastructure/databases/graph/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class GraphConfig(BaseSettings):
graph_filename
)
graph_model: object = KnowledgeGraph
graph_topology_task: bool = False
graph_topology: object = KnowledgeGraph
graph_topology_task: bool = True
graph_topology_model: object = KnowledgeGraph
infer_graph_topology: bool = True
topology_file_path: str = os.path.join(
os.path.join(get_absolute_path(".cognee_system"), "databases"),
Expand All @@ -39,6 +39,7 @@ def to_dict(self) -> dict:
"graph_database_password": self.graph_database_password,
"graph_database_port": self.graph_database_port,
"infer_graph_topology": self.infer_graph_topology,
"graph_topology_task": self.graph_topology_task,
}


Expand Down
4 changes: 3 additions & 1 deletion cognee/infrastructure/llm/prompts/extract_topology.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
You are a topology master and need to extract the following topology information from the text provided to you.
Relationship parts can't be empty, and have to be logical AND CONNECTING ELEMENTS OF THE TOPOLOGY
The source is the parent of the target. And the target is the child of the source.
Have in mind this model needs to become a graph later, and USE EXISTING IDS AS NODE IDS
Have in mind this model needs to become a graph later, and USE EXISTING IDS AS NODE IDS
You are just connecting documents, you don't need to decompose the documents into words or anything like that.
Use document id as name if name is not present
2 changes: 1 addition & 1 deletion cognee/modules/topology/infer_data_topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
async def infer_data_topology(content: str, graph_topology=None):
if graph_topology is None:
graph_config = get_graph_config()
graph_topology = graph_config.graph_topology
graph_topology = graph_config.graph_topology_model

print("content: ", type(content))
try:
Expand Down

0 comments on commit 16139f7

Please sign in to comment.