Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions cognee/infrastructure/databases/hybrid/falkordb/FalkorDBAdapter.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import asyncio
# from datetime import datetime
import json
from uuid import UUID
from textwrap import dedent
from uuid import UUID

from falkordb import FalkorDB

from cognee.exceptions import InvalidValueError
from cognee.infrastructure.engine import DataPoint
from cognee.infrastructure.databases.graph.graph_db_interface import GraphDBInterface
from cognee.infrastructure.databases.graph.graph_db_interface import \
GraphDBInterface
from cognee.infrastructure.databases.vector.embeddings import EmbeddingEngine
from cognee.infrastructure.databases.vector.vector_db_interface import VectorDBInterface
from cognee.infrastructure.databases.vector.vector_db_interface import \
VectorDBInterface
from cognee.infrastructure.engine import DataPoint


class IndexSchema(DataPoint):
text: str

_metadata: dict = {
"index_fields": ["text"]
"index_fields": ["text"],
"type": "IndexSchema"
}

class FalkorDBAdapter(VectorDBInterface, GraphDBInterface):
Expand Down
14 changes: 9 additions & 5 deletions cognee/infrastructure/databases/vector/lancedb/LanceDBAdapter.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
from typing import List, Optional, get_type_hints, Generic, TypeVar
import asyncio
from typing import Generic, List, Optional, TypeVar, get_type_hints
from uuid import UUID

import lancedb
from lancedb.pydantic import LanceModel, Vector
from pydantic import BaseModel
from lancedb.pydantic import Vector, LanceModel

from cognee.exceptions import InvalidValueError
from cognee.infrastructure.engine import DataPoint
from cognee.infrastructure.files.storage import LocalStorage
from cognee.modules.storage.utils import copy_model, get_own_properties

from ..embeddings.EmbeddingEngine import EmbeddingEngine
from ..models.ScoredResult import ScoredResult
from ..vector_db_interface import VectorDBInterface
from ..utils import normalize_distances
from ..embeddings.EmbeddingEngine import EmbeddingEngine
from ..vector_db_interface import VectorDBInterface


class IndexSchema(DataPoint):
id: str
text: str

_metadata: dict = {
"index_fields": ["text"]
"index_fields": ["text"],
"type": "IndexSchema"
}

class LanceDBAdapter(VectorDBInterface):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import logging
from typing import List, Optional
from uuid import UUID

from cognee.infrastructure.engine import DataPoint
from ..vector_db_interface import VectorDBInterface
from ..models.ScoredResult import ScoredResult

from ..embeddings.EmbeddingEngine import EmbeddingEngine
from ..models.ScoredResult import ScoredResult
from ..vector_db_interface import VectorDBInterface

logger = logging.getLogger("MilvusAdapter")

Expand All @@ -16,7 +18,8 @@ class IndexSchema(DataPoint):
text: str

_metadata: dict = {
"index_fields": ["text"]
"index_fields": ["text"],
"type": "IndexSchema"
}


Expand Down
21 changes: 12 additions & 9 deletions cognee/infrastructure/databases/vector/pgvector/PGVectorAdapter.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
import asyncio
from uuid import UUID
from typing import List, Optional, get_type_hints
from uuid import UUID

from sqlalchemy import JSON, Column, Table, delete, select
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy import JSON, Column, Table, select, delete
from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker

from cognee.exceptions import InvalidValueError
from cognee.infrastructure.databases.exceptions import EntityNotFoundError
from cognee.infrastructure.engine import DataPoint

from .serialize_data import serialize_data
from ...relational.ModelBase import Base
from ...relational.sqlalchemy.SqlAlchemyAdapter import SQLAlchemyAdapter
from ..embeddings.EmbeddingEngine import EmbeddingEngine
from ..models.ScoredResult import ScoredResult
from ..vector_db_interface import VectorDBInterface
from ..utils import normalize_distances
from ..embeddings.EmbeddingEngine import EmbeddingEngine
from ...relational.sqlalchemy.SqlAlchemyAdapter import SQLAlchemyAdapter
from ...relational.ModelBase import Base
from ..vector_db_interface import VectorDBInterface
from .serialize_data import serialize_data


class IndexSchema(DataPoint):
text: str

_metadata: dict = {
"index_fields": ["text"]
"index_fields": ["text"],
"type": "IndexSchema"
}

def singleton(class_):
Expand Down
12 changes: 8 additions & 4 deletions cognee/infrastructure/databases/vector/qdrant/QDrantAdapter.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import logging
from typing import Dict, List, Optional
from uuid import UUID
from typing import List, Dict, Optional

from qdrant_client import AsyncQdrantClient, models

from cognee.exceptions import InvalidValueError
from cognee.infrastructure.databases.vector.models.ScoredResult import ScoredResult
from cognee.infrastructure.databases.vector.models.ScoredResult import \
ScoredResult
from cognee.infrastructure.engine import DataPoint
from ..vector_db_interface import VectorDBInterface

from ..embeddings.EmbeddingEngine import EmbeddingEngine
from ..vector_db_interface import VectorDBInterface

logger = logging.getLogger("QDrantAdapter")

class IndexSchema(DataPoint):
text: str

_metadata: dict = {
"index_fields": ["text"]
"index_fields": ["text"],
"type": "IndexSchema"
}

# class CollectionConfig(BaseModel, extra = "forbid"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@

from cognee.exceptions import InvalidValueError
from cognee.infrastructure.engine import DataPoint
from ..vector_db_interface import VectorDBInterface
from ..models.ScoredResult import ScoredResult

from ..embeddings.EmbeddingEngine import EmbeddingEngine
from ..models.ScoredResult import ScoredResult
from ..vector_db_interface import VectorDBInterface

logger = logging.getLogger("WeaviateAdapter")

class IndexSchema(DataPoint):
text: str

_metadata: dict = {
"index_fields": ["text"]
"index_fields": ["text"],
"type": "IndexSchema"
}

class WeaviateAdapter(VectorDBInterface):
Expand Down
13 changes: 8 additions & 5 deletions cognee/infrastructure/engine/models/DataPoint.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from typing_extensions import TypedDict
from uuid import UUID, uuid4
from typing import Optional
from datetime import datetime, timezone
from typing import Optional
from uuid import UUID, uuid4

from pydantic import BaseModel, Field
from typing_extensions import TypedDict


class MetaData(TypedDict):
index_fields: list[str]
Expand All @@ -13,7 +15,8 @@ class DataPoint(BaseModel):
updated_at: Optional[datetime] = datetime.now(timezone.utc)
topological_rank: Optional[int] = 0
_metadata: Optional[MetaData] = {
"index_fields": []
"index_fields": [],
"type": "DataPoint"
}

# class Config:
Expand All @@ -39,4 +42,4 @@ def get_embeddable_properties(self, data_point):

@classmethod
def get_embeddable_property_names(self, data_point):
return data_point._metadata["index_fields"] or []
return data_point._metadata["index_fields"] or []
3 changes: 3 additions & 0 deletions cognee/modules/chunking/models/DocumentChunk.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from typing import List, Optional

from cognee.infrastructure.engine import DataPoint
from cognee.modules.data.processing.document_types import Document
from cognee.modules.engine.models import Entity


class DocumentChunk(DataPoint):
__tablename__ = "document_chunk"
text: str
Expand All @@ -14,4 +16,5 @@ class DocumentChunk(DataPoint):

_metadata: Optional[dict] = {
"index_fields": ["text"],
"type": "DocumentChunk"
}
10 changes: 7 additions & 3 deletions cognee/modules/data/processing/document_types/Document.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
from cognee.infrastructure.engine import DataPoint
from uuid import UUID

from cognee.infrastructure.engine import DataPoint


class Document(DataPoint):
type: str
name: str
raw_data_location: str
metadata_id: UUID
mime_type: str
_metadata: dict = {
"type": "Document"
}

def read(self, chunk_size: int) -> str:
pass
pass
1 change: 1 addition & 0 deletions cognee/modules/engine/models/Entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ class Entity(DataPoint):

_metadata: dict = {
"index_fields": ["name"],
"type": "Entity"
}
3 changes: 2 additions & 1 deletion cognee/modules/engine/models/EntityType.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from cognee.infrastructure.engine import DataPoint


class EntityType(DataPoint):
__tablename__ = "entity_type"
name: str
type: str
description: str

_metadata: dict = {
"index_fields": ["name"],
"type": "EntityType"
}
3 changes: 3 additions & 0 deletions cognee/modules/graph/models/EdgeType.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from typing import Optional

from cognee.infrastructure.engine import DataPoint


class EdgeType(DataPoint):
__tablename__ = "edge_type"
relationship_name: str
number_of_edges: int

_metadata: Optional[dict] = {
"index_fields": ["relationship_name"],
"type": "EdgeType"
}
2 changes: 1 addition & 1 deletion cognee/modules/graph/utils/convert_node_to_data_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


def convert_node_to_data_point(node_data: dict) -> DataPoint:
subclass = find_subclass_by_name(DataPoint, node_data["type"])
subclass = find_subclass_by_name(DataPoint, node_data._metadata["type"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Ensure node_data has _metadata attribute with "type" key

The change accesses node_data._metadata["type"] instead of node_data["type"]. Verify that node_data is an object with an _metadata attribute containing the "type" key. If node_data is a dictionary, this change may cause an AttributeError.

Consider adding a check to ensure that _metadata exists and handle cases where node_data might not have this attribute.


return subclass(**node_data)

Expand Down
21 changes: 14 additions & 7 deletions cognee/shared/CodeGraphEntities.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,47 @@
from typing import List, Optional

from cognee.infrastructure.engine import DataPoint


class Repository(DataPoint):
__tablename__ = "Repository"
path: str
type: Optional[str] = "Repository"
_metadata: dict = {
"index_fields": ["source_code"],
"type": "Repository"
}

class CodeFile(DataPoint):
__tablename__ = "codefile"
extracted_id: str # actually file path
type: Optional[str] = "CodeFile"
source_code: Optional[str] = None
part_of: Optional[Repository] = None
depends_on: Optional[List["CodeFile"]] = None
depends_directly_on: Optional[List["CodeFile"]] = None
contains: Optional[List["CodePart"]] = None

_metadata: dict = {
"index_fields": ["source_code"]
"index_fields": ["source_code"],
"type": "CodeFile"
}

class CodePart(DataPoint):
__tablename__ = "codepart"
# part_of: Optional[CodeFile]
source_code: str
type: Optional[str] = "CodePart"


_metadata: dict = {
"index_fields": ["source_code"]
"index_fields": ["source_code"],
"type": "CodePart"
}

class CodeRelationship(DataPoint):
source_id: str
target_id: str
type: str # between files
relation: str # depends on or depends directly
_metadata: dict = {
"type": "CodeRelationship"
}

CodeFile.model_rebuild()
CodePart.model_rebuild()
Loading
Loading