feat: adds end to end concurrent subprocess cognify test
This commit is contained in:
parent
40acb6e4e3
commit
33b97215ce
3 changed files with 90 additions and 4 deletions
31
cognee/tests/subprocesses/simple_cognify_1.py
Normal file
31
cognee/tests/subprocesses/simple_cognify_1.py
Normal file
|
|
@ -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())
|
||||
31
cognee/tests/subprocesses/simple_cognify_2.py
Normal file
31
cognee/tests/subprocesses/simple_cognify_2.py
Normal file
|
|
@ -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())
|
||||
|
|
@ -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())
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue