diff --git a/cognee/tests/subprocesses/simple_cognify_1.py b/cognee/tests/subprocesses/simple_cognify_1.py new file mode 100644 index 000000000..cf4d65c88 --- /dev/null +++ b/cognee/tests/subprocesses/simple_cognify_1.py @@ -0,0 +1,31 @@ +import asyncio +import cognee +from cognee.shared.logging_utils import setup_logging, INFO +from cognee.api.v1.search import SearchType + + +async def main(): + await cognee.cognify(datasets=["first_cognify_dataset"]) + + query_text = ( + "Tell me what is in the context. Additionally write out 'FIRST_COGNIFY' before your answer" + ) + search_results = await cognee.search( + query_type=SearchType.GRAPH_COMPLETION, + query_text=query_text, + datasets=["first_cognify_dataset"], + ) + + print("Search results:") + for result_text in search_results: + print(result_text) + + +if __name__ == "__main__": + logger = setup_logging(log_level=INFO) + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + try: + loop.run_until_complete(main()) + finally: + loop.run_until_complete(loop.shutdown_asyncgens()) diff --git a/cognee/tests/subprocesses/simple_cognify_2.py b/cognee/tests/subprocesses/simple_cognify_2.py new file mode 100644 index 000000000..6de5035ec --- /dev/null +++ b/cognee/tests/subprocesses/simple_cognify_2.py @@ -0,0 +1,31 @@ +import asyncio +import cognee +from cognee.shared.logging_utils import setup_logging, INFO +from cognee.api.v1.search import SearchType + + +async def main(): + await cognee.cognify(datasets=["second_cognify_dataset"]) + + query_text = ( + "Tell me what is in the context. Additionally write out 'SECOND_COGNIFY' before your answer" + ) + search_results = await cognee.search( + query_type=SearchType.GRAPH_COMPLETION, + query_text=query_text, + datasets=["second_cognify_dataset"], + ) + + print("Search results:") + for result_text in search_results: + print(result_text) + + +if __name__ == "__main__": + logger = setup_logging(log_level=INFO) + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + try: + loop.run_until_complete(main()) + finally: + loop.run_until_complete(loop.shutdown_asyncgens()) diff --git a/cognee/tests/test_concurrent_subprocess_access.py b/cognee/tests/test_concurrent_subprocess_access.py index 0121b1af7..16187eb4d 100644 --- a/cognee/tests/test_concurrent_subprocess_access.py +++ b/cognee/tests/test_concurrent_subprocess_access.py @@ -4,11 +4,7 @@ import cognee import pathlib import subprocess -from cognee.infrastructure.databases.graph import get_graph_engine -from collections import Counter -from cognee.modules.users.methods import get_default_user from cognee.shared.logging_utils import get_logger -from multiprocessing import Process logger = get_logger() @@ -47,6 +43,34 @@ async def concurrent_subprocess_access(): writer_process.wait() reader_process.wait() + logger.info(f"Basic write read subprocess example finished") + + await cognee.prune.prune_data() + await cognee.prune.prune_system(metadata=True) + + text = """ + This is the text of the first cognify subprocess + """ + await cognee.add(text, dataset_name="first_cognify_dataset") + + text = """ + This is the text of the second cognify subprocess + """ + await cognee.add(text, dataset_name="second_cognify_dataset") + + first_cognify_path = subprocess_directory_path + "/simple_cognify_1.py" + second_cognify_path = subprocess_directory_path + "/simple_cognify_2.py" + + first_cognify_process = subprocess.Popen([os.sys.executable, str(first_cognify_path)]) + + second_cognify_process = subprocess.Popen([os.sys.executable, str(second_cognify_path)]) + + # Wait for both processes to complete + first_cognify_process.wait() + second_cognify_process.wait() + + logger.info(f"Database concurrent subprocess example finished") + if __name__ == "__main__": asyncio.run(concurrent_subprocess_access())