welearn-database 0.2.1__tar.gz → 0.2.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. {welearn_database-0.2.1 → welearn_database-0.2.3}/PKG-INFO +1 -1
  2. {welearn_database-0.2.1 → welearn_database-0.2.3}/pyproject.toml +1 -1
  3. {welearn_database-0.2.1 → welearn_database-0.2.3}/welearn_database/data/enumeration.py +7 -1
  4. {welearn_database-0.2.1 → welearn_database-0.2.3}/welearn_database/data/models/__init__.py +18 -7
  5. welearn_database-0.2.3/welearn_database/data/models/agent_related.py +78 -0
  6. {welearn_database-0.2.1 → welearn_database-0.2.3}/welearn_database/data/models/document_related.py +70 -17
  7. welearn_database-0.2.1/welearn_database/data/models/agent_related.py +0 -0
  8. {welearn_database-0.2.1 → welearn_database-0.2.3}/LICENSE +0 -0
  9. {welearn_database-0.2.1 → welearn_database-0.2.3}/README.md +0 -0
  10. {welearn_database-0.2.1 → welearn_database-0.2.3}/welearn_database/__init__.py +0 -0
  11. {welearn_database-0.2.1 → welearn_database-0.2.3}/welearn_database/alembic/README +0 -0
  12. {welearn_database-0.2.1 → welearn_database-0.2.3}/welearn_database/alembic/env.py +0 -0
  13. {welearn_database-0.2.1 → welearn_database-0.2.3}/welearn_database/alembic/script.py.mako +0 -0
  14. {welearn_database-0.2.1 → welearn_database-0.2.3}/welearn_database/alembic/versions/16ff997426d3_remove_error_retrieval_unique_constraint.py +0 -0
  15. {welearn_database-0.2.1 → welearn_database-0.2.3}/welearn_database/alembic/versions/4c7161819e5a_grafana_views.py +0 -0
  16. {welearn_database-0.2.1 → welearn_database-0.2.3}/welearn_database/alembic/versions/4fcbfb7f3145_added_api_key_management_table.py +0 -0
  17. {welearn_database-0.2.1 → welearn_database-0.2.3}/welearn_database/alembic/versions/5d82613c9aca_context_document.py +0 -0
  18. {welearn_database-0.2.1 → welearn_database-0.2.3}/welearn_database/alembic/versions/821173cf9c5d_initial_migration.py +0 -0
  19. {welearn_database-0.2.1 → welearn_database-0.2.3}/welearn_database/alembic/versions/89920abb7ff8_add_category.py +0 -0
  20. {welearn_database-0.2.1 → welearn_database-0.2.3}/welearn_database/alembic/versions/a50a1db3ca2a_add_used_since_column_for_embeddings.py +0 -0
  21. {welearn_database-0.2.1 → welearn_database-0.2.3}/welearn_database/alembic/versions/b031206324b7_agent_related.py +0 -0
  22. {welearn_database-0.2.1 → welearn_database-0.2.3}/welearn_database/alembic/versions/e354666f951d_inferred_user.py +0 -0
  23. {welearn_database-0.2.1 → welearn_database-0.2.3}/welearn_database/data/__init__.py +0 -0
  24. {welearn_database-0.2.1 → welearn_database-0.2.3}/welearn_database/data/models/corpus_related.py +0 -0
  25. {welearn_database-0.2.1 → welearn_database-0.2.3}/welearn_database/data/models/grafana.py +0 -0
  26. {welearn_database-0.2.1 → welearn_database-0.2.3}/welearn_database/data/models/user_related.py +0 -0
  27. {welearn_database-0.2.1 → welearn_database-0.2.3}/welearn_database/database_utils.py +0 -0
  28. {welearn_database-0.2.1 → welearn_database-0.2.3}/welearn_database/exceptions.py +0 -0
  29. {welearn_database-0.2.1 → welearn_database-0.2.3}/welearn_database/modules/__init__.py +0 -0
  30. {welearn_database-0.2.1 → welearn_database-0.2.3}/welearn_database/modules/text_cleaning.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: welearn-database
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: All stuff related to relationnal database from the WeLearn project
5
5
  License: cc-by-sa-nc
6
6
  Author: Théo
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "welearn-database"
3
- version = "0.2.1"
3
+ version = "0.2.3"
4
4
  description = "All stuff related to relationnal database from the WeLearn project"
5
5
  authors = [
6
6
  {name = "Théo",email = "theo.nardin@cri-paris.org"}
@@ -18,6 +18,12 @@ class Counter(Enum):
18
18
 
19
19
  class DbSchemaEnum(StrEnum):
20
20
  GRAFANA = auto()
21
+ AGENT_RELATED = auto()
21
22
  CORPUS_RELATED = auto()
22
23
  DOCUMENT_RELATED = auto()
23
- USER_RELATED = auto()
24
+ USER_RELATED = auto()
25
+
26
+ class ContextType(StrEnum):
27
+ INTRODUCTION = auto()
28
+ TARGET = auto()
29
+ SUBJECT = auto()
@@ -2,10 +2,16 @@ from datetime import datetime
2
2
  from typing import Any
3
3
 
4
4
  from sqlalchemy import types
5
- from sqlalchemy.dialects.postgresql import TIMESTAMP
5
+ from sqlalchemy.dialects.postgresql import ARRAY, TIMESTAMP
6
+ from sqlalchemy.ext.compiler import compiles
6
7
  from sqlalchemy.orm import DeclarativeBase
7
8
 
8
9
 
10
+ @compiles(ARRAY, "sqlite")
11
+ def compile_binary_sqlite(type_, compiler, **kw):
12
+ return "TEXT"
13
+
14
+
9
15
  class Base(DeclarativeBase):
10
16
  type_annotation_map = {
11
17
  dict[str, Any]: types.JSON,
@@ -18,12 +24,17 @@ class Base(DeclarativeBase):
18
24
  Raise an exception if attempting to assign to an atribute of a "read-only" object
19
25
  Transient attributes need to be prefixed with "_t_"
20
26
  """
21
- if (getattr(self, '__read_only__', False)
22
- and name != "_sa_instance_state"
23
- and not name.startswith("_t_")):
24
- raise ValueError("Trying to assign to %s of a read-only object %s" % (name, self))
27
+ if (
28
+ getattr(self, "__read_only__", False)
29
+ and name != "_sa_instance_state"
30
+ and not name.startswith("_t_")
31
+ ):
32
+ raise ValueError(
33
+ "Trying to assign to %s of a read-only object %s" % (name, self)
34
+ )
25
35
  super(Base, self).__setattr__(name, value)
26
36
 
27
- from .document_related import *
37
+
28
38
  from .corpus_related import *
29
- from .user_related import *
39
+ from .document_related import *
40
+ from .user_related import *
@@ -0,0 +1,78 @@
1
+ from typing import Any, Dict, Optional
2
+
3
+ from sqlalchemy import Index, Text
4
+ from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
5
+ from sqlalchemy.dialects.postgresql import JSONB
6
+ from sqlalchemy import text
7
+ from sqlalchemy.types import LargeBinary, Integer
8
+
9
+ from welearn_database.data.enumeration import DbSchemaEnum
10
+ from welearn_database.data.models import Base
11
+
12
+
13
+ schema_name = DbSchemaEnum.AGENT_RELATED.value
14
+
15
+
16
+ class CheckpointBlobs(Base):
17
+ __tablename__ = "checkpoint_blobs"
18
+ __table_args__ = (
19
+ Index("checkpoint_blobs_thread_id_idx", "thread_id"),
20
+ {"schema": schema_name},
21
+ )
22
+
23
+ thread_id: Mapped[str] = mapped_column(Text, primary_key=True, nullable=False)
24
+ checkpoint_ns: Mapped[str] = mapped_column(
25
+ Text, server_default=text("''::text"), primary_key=True, nullable=False
26
+ )
27
+ channel: Mapped[str] = mapped_column(Text, primary_key=True, nullable=False)
28
+ version_: Mapped[str] = mapped_column("version", Text, primary_key=True, nullable=False)
29
+ type_: Mapped[str] = mapped_column("type", Text, nullable=False)
30
+ blob: Mapped[Optional[bytes]] = mapped_column(LargeBinary, nullable=True)
31
+
32
+
33
+ class CheckpointMigrations(Base):
34
+ __tablename__ = "checkpoint_migrations"
35
+ __table_args__ = {"schema": schema_name},
36
+
37
+ v: Mapped[int] = mapped_column(Integer, primary_key=True, nullable=False)
38
+
39
+
40
+ class CheckpointWrites(Base):
41
+ __tablename__ = "checkpoint_writes"
42
+ __table_args__ = (
43
+ Index("checkpoint_writes_thread_id_idx", "thread_id"),
44
+ {"schema": schema_name},
45
+ )
46
+
47
+ thread_id: Mapped[str] = mapped_column(Text, primary_key=True, nullable=False)
48
+ checkpoint_ns: Mapped[str] = mapped_column(
49
+ Text, server_default=text("''::text"), primary_key=True, nullable=False
50
+ )
51
+ checkpoint_id: Mapped[str] = mapped_column(Text, primary_key=True, nullable=False)
52
+ task_id: Mapped[str] = mapped_column(Text, primary_key=True, nullable=False)
53
+ idx: Mapped[int] = mapped_column(Integer, primary_key=True, nullable=False)
54
+
55
+ channel: Mapped[str] = mapped_column(Text, nullable=False)
56
+ type_: Mapped[Optional[str]] = mapped_column("type", Text, nullable=True)
57
+ blob: Mapped[bytes] = mapped_column(LargeBinary, nullable=False)
58
+ task_path: Mapped[str] = mapped_column(
59
+ Text, server_default=text("''::text"), nullable=False
60
+ )
61
+
62
+
63
+ class Checkpoints(Base):
64
+ __tablename__ = "checkpoints"
65
+ __table_args__ = {"schema": schema_name},
66
+
67
+ thread_id: Mapped[str] = mapped_column(Text, primary_key=True, nullable=False)
68
+ checkpoint_ns: Mapped[str] = mapped_column(
69
+ Text, server_default=text("''::text"), primary_key=True, nullable=False
70
+ )
71
+ checkpoint_id: Mapped[str] = mapped_column(Text, primary_key=True, nullable=False)
72
+
73
+ parent_checkpoint_id: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
74
+ type_: Mapped[Optional[str]] = mapped_column("type", Text, nullable=True)
75
+ checkpoint: Mapped[Dict[str, Any]] = mapped_column(JSONB, nullable=False)
76
+ metadata_: Mapped[Dict[str, Any]] = mapped_column("metadata",
77
+ JSONB, server_default=text("'{}'::jsonb"), nullable=False
78
+ )
@@ -4,16 +4,21 @@ from urllib.parse import urlparse
4
4
  from uuid import UUID
5
5
  from zlib import adler32
6
6
 
7
- from sqlalchemy import types, ForeignKey, UniqueConstraint, func, LargeBinary
8
- from sqlalchemy.dialects.postgresql import TIMESTAMP, ENUM
7
+ from sqlalchemy import ForeignKey, Integer, LargeBinary, UniqueConstraint, func, types
8
+ from sqlalchemy.dialects.postgresql import ARRAY, ENUM, TIMESTAMP
9
9
  from sqlalchemy.ext.hybrid import hybrid_property
10
- from sqlalchemy.orm import mapped_column, Mapped, relationship, validates
11
-
12
- from welearn_database.modules.text_cleaning import clean_text
13
- from welearn_database.data.enumeration import DbSchemaEnum, Step, Counter
14
- from welearn_database.data.models.corpus_related import Corpus, NClassifierModel, BiClassifierModel, EmbeddingModel
15
- from . import Base
10
+ from sqlalchemy.orm import Mapped, mapped_column, relationship, validates
11
+
12
+ from welearn_database.data.enumeration import ContextType, Counter, DbSchemaEnum, Step
13
+ from welearn_database.data.models import Base
14
+ from welearn_database.data.models.corpus_related import (
15
+ BiClassifierModel,
16
+ Corpus,
17
+ EmbeddingModel,
18
+ NClassifierModel,
19
+ )
16
20
  from welearn_database.exceptions import InvalidURLScheme
21
+ from welearn_database.modules.text_cleaning import clean_text
17
22
 
18
23
  schema_name = DbSchemaEnum.DOCUMENT_RELATED.value
19
24
 
@@ -34,6 +39,7 @@ class WeLearnDocument(Base):
34
39
  :cvar updated_at: The timestamp when the document was last updated.
35
40
  :cvar corpus: The relationship to the Corpus object.
36
41
  """
42
+
37
43
  __tablename__ = "welearn_document"
38
44
  __table_args__ = (
39
45
  UniqueConstraint("url", name="welearn_document_url_key"),
@@ -46,8 +52,8 @@ class WeLearnDocument(Base):
46
52
  url: Mapped[str] = mapped_column(nullable=False)
47
53
  title: Mapped[str | None]
48
54
  lang: Mapped[str | None]
49
- _description: Mapped[str]
50
- _full_content: Mapped[str]
55
+ _description: Mapped[str | None]
56
+ _full_content: Mapped[str | None]
51
57
  details: Mapped[dict[str, Any] | None]
52
58
  _trace: Mapped[int | None] = mapped_column(types.BIGINT)
53
59
  corpus_id: Mapped[UUID] = mapped_column(
@@ -83,9 +89,7 @@ class WeLearnDocument(Base):
83
89
  parsed_url = urlparse(url=value)
84
90
  accepted_scheme = ["https"]
85
91
  if parsed_url.scheme not in accepted_scheme or len(parsed_url.netloc) == 0:
86
- raise InvalidURLScheme(
87
- "There is an error on the URL form : %s", value
88
- )
92
+ raise InvalidURLScheme("There is an error on the URL form : %s", value)
89
93
  return value
90
94
 
91
95
  @validates("_full_content")
@@ -98,7 +102,7 @@ class WeLearnDocument(Base):
98
102
  :raises ValueError: If the full content is too short.
99
103
  """
100
104
  if not value:
101
- raise ValueError("Full content cannot be empty or None")
105
+ return value
102
106
  if len(value) < 25:
103
107
  raise ValueError(f"Content is too short : {len(value)}")
104
108
  return value
@@ -118,7 +122,7 @@ class WeLearnDocument(Base):
118
122
  @description.setter
119
123
  def description(self, description):
120
124
  if not description:
121
- raise ValueError("Description cannot be empty or None")
125
+ self._description = description
122
126
  self._description = clean_text(description)
123
127
 
124
128
  @hybrid_property
@@ -136,6 +140,7 @@ class ProcessState(Base):
136
140
  :cvar operation_order: A bigint representing the order of operations for the process state.
137
141
  :cvar document: The relationship to the WeLearnDocument object.
138
142
  """
143
+
139
144
  __tablename__ = "process_state"
140
145
  __table_args__ = {"schema": schema_name}
141
146
 
@@ -173,7 +178,7 @@ class Keyword(Base):
173
178
  __tablename__ = "keyword"
174
179
  __table_args__ = (
175
180
  UniqueConstraint("keyword", name="keyword_unique"),
176
- {"schema": schema_name}
181
+ {"schema": schema_name},
177
182
  )
178
183
 
179
184
  id: Mapped[UUID] = mapped_column(
@@ -314,7 +319,6 @@ class AnalyticCounter(Base):
314
319
  document: Mapped["WeLearnDocument"] = relationship()
315
320
 
316
321
 
317
-
318
322
  class CorpusEmbeddingModel(Base):
319
323
  __tablename__ = "corpus_embedding_model"
320
324
  __table_args__ = (
@@ -451,6 +455,55 @@ class Sdg(Base):
451
455
  n_classifier_model: Mapped["NClassifierModel"] = relationship()
452
456
  slice: Mapped["DocumentSlice"] = relationship()
453
457
 
458
+
459
+ class ContextDocument(Base):
460
+ __tablename__ = "context_document"
461
+
462
+ id = mapped_column(
463
+ types.Uuid,
464
+ primary_key=True,
465
+ server_default="gen_random_uuid()",
466
+ nullable=False,
467
+ )
468
+ url: Mapped[str]
469
+ title: Mapped[str]
470
+ full_content: Mapped[str]
471
+ embedding_model_id = mapped_column(
472
+ types.Uuid,
473
+ ForeignKey(f"{DbSchemaEnum.CORPUS_RELATED.value}.embedding_model.id"),
474
+ )
475
+ sdg_related: Mapped[list[int]] = mapped_column(ARRAY(Integer))
476
+ created_at: Mapped[datetime] = mapped_column(
477
+ TIMESTAMP(timezone=False),
478
+ nullable=False,
479
+ default=func.localtimestamp(),
480
+ server_default="NOW()",
481
+ )
482
+ embedding: Mapped[bytes] = mapped_column(LargeBinary)
483
+
484
+ updated_at: Mapped[datetime] = mapped_column(
485
+ TIMESTAMP(timezone=False),
486
+ nullable=False,
487
+ default=func.localtimestamp(),
488
+ onupdate=func.localtimestamp(),
489
+ )
490
+
491
+ context_type: Mapped[str] = mapped_column(
492
+ ENUM(
493
+ *(e.value.lower() for e in ContextType),
494
+ name="context_type",
495
+ schema="document_related",
496
+ ),
497
+ nullable=False,
498
+ )
499
+ embedding_model = relationship("EmbeddingModel", foreign_keys=[embedding_model_id])
500
+
501
+ __table_args__ = (
502
+ UniqueConstraint("url", name="meta_document_url_key"),
503
+ {"schema": "document_related"},
504
+ )
505
+
506
+
454
507
  # Views
455
508
  class QtyDocumentInQdrant(Base):
456
509
  __tablename__ = "qty_document_in_qdrant"