Files
wehub-resource-sync c889a57b6b
Test Suites / Build CI Environment (push) Has been cancelled
Test Suites / Basic Tests (push) Has been cancelled
Test Suites / End-to-End Tests (push) Has been cancelled
Test Suites / CLI Tests (push) Has been cancelled
Test Suites / Slow End-to-End Tests (push) Has been cancelled
Test Suites / Graph Database Tests (push) Has been cancelled
Test Suites / Vector DB Tests (push) Has been cancelled
Test Suites / Temporal Graph Test (push) Has been cancelled
Test Suites / Search Test on Different DBs (push) Has been cancelled
Test Suites / Example Tests (push) Has been cancelled
Test Suites / Notebook Tests (push) Has been cancelled
Test Suites / OS and Python Tests Ubuntu (push) Has been cancelled
Test Suites / OS and Python Tests Extended (push) Has been cancelled
Test Suites / LLM Test Suite (push) Has been cancelled
Test Suites / S3 File Storage Test (push) Has been cancelled
Test Suites / Run Integration Tests (push) Has been cancelled
Test Suites / MCP Tests (push) Has been cancelled
Test Suites / Docker Compose Test (push) Has been cancelled
Test Suites / Docker CI test (push) Has been cancelled
Test Suites / Relational DB Migration Tests (push) Has been cancelled
Test Suites / Distributed Cognee Test (push) Has been cancelled
Test Suites / DB Examples Tests (push) Has been cancelled
Test Suites / Test Completion Status (push) Has been cancelled
Test Suites / Claude Code Review (push) Has been cancelled
Test Suites / basic checks (push) Has been cancelled
build | Build and Push Cognee MCP Docker Image to dockerhub / docker-build-and-push (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
build | Build and Push Docker Image to dockerhub / docker-build-and-push (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Core Functionality (3.11) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Core Functionality (3.12) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges with Different Graph Databases (kuzu, kuzu) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges with Different Graph Databases (neo4j, neo4j) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Examples (push) Has been cancelled
Weighted Edges Tests / Code Quality for Weighted Edges (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:02:24 +08:00

104 lines
3.4 KiB
Python
Executable File

import os
import pathlib
import cognee
from cognee.modules.search.operations import get_history
from cognee.modules.users.methods import get_default_user
from cognee.shared.logging_utils import get_logger
from cognee.modules.search.types import SearchType
from cognee.low_level import DataPoint
logger = get_logger()
async def main():
# Define a custom graph model for programming languages.
class FieldType(DataPoint):
name: str = "Field"
metadata: dict = {"index_fields": ["name"]}
class Field(DataPoint):
name: str
is_type: FieldType
metadata: dict = {"index_fields": ["name"]}
class ProgrammingLanguageType(DataPoint):
name: str = "Programming Language"
metadata: dict = {"index_fields": ["name"]}
class ProgrammingLanguage(DataPoint):
name: str
used_in: list[Field] = []
is_type: ProgrammingLanguageType
metadata: dict = {"index_fields": ["name"]}
data_directory_path = str(
pathlib.Path(
os.path.join(pathlib.Path(__file__).parent, ".data_storage/test_custom_model")
).resolve()
)
cognee.config.data_root_directory(data_directory_path)
cognee_directory_path = str(
pathlib.Path(
os.path.join(pathlib.Path(__file__).parent, ".cognee_system/test_custom_model")
).resolve()
)
cognee.config.system_root_directory(cognee_directory_path)
await cognee.prune.prune_data()
await cognee.prune.prune_system(metadata=True)
text = (
"Python is an interpreted, high-level, general-purpose programming language. It was created by Guido van Rossum and first released in 1991. "
+ "Python is widely used in data analysis, web development, and machine learning."
)
await cognee.add(text)
await cognee.cognify(graph_model=ProgrammingLanguage)
graph_file_path = str(
pathlib.Path(
os.path.join(
pathlib.Path(__file__).parent,
".artifacts/test_custom_model/graph_visualization.html",
)
).resolve()
)
await cognee.visualize_graph(graph_file_path)
# Completion query that uses graph data to form context.
completion = await cognee.search("What is python?", SearchType.GRAPH_COMPLETION)
assert len(completion) != 0, "Graph completion search didn't return any result."
print("Graph completion result is:")
print(completion)
# Completion query that uses document chunks to form context.
completion = await cognee.search("What is Python?", SearchType.RAG_COMPLETION)
assert len(completion) != 0, "Completion search didn't return any result."
print("Completion result is:")
print(completion)
# Query all summaries related to query.
summaries = await cognee.search("Python", SearchType.SUMMARIES)
assert len(summaries) != 0, "Summaries search didn't return any results."
print("Summary results are:")
for summary in summaries:
print(summary)
chunks = await cognee.search("Python", SearchType.CHUNKS)
assert len(chunks) != 0, "Chunks search didn't return any results."
print("Chunk results are:")
for chunk in chunks:
print(chunk)
user = await get_default_user()
history = await get_history(user.id)
assert len(history) == 8, "Search history is not correct."
if __name__ == "__main__":
import asyncio
asyncio.run(main(), debug=True)