Files
kotaemon/libs/ktem/ktem/db/models.py
Duc Nguyen (john) 8a90fcfc99 Restructure index to allow it to be dynamically created by end-user (#151)
1. Introduce the concept of "collection_name" to docstore and vector store. Each collection can be viewed similarly to a table in a SQL database. It allows better organizing information within this data source.
2. Move the `Index` and `Source` tables from the application scope into the index scope. For each new index created by user, these tables should increase accordingly. So it depends on the index, rather than the app.
3. Make each index responsible for the UI components in the app.
4. Construct the File UI page.
2024-03-07 01:50:47 +07:00

50 lines
1.3 KiB
Python

import ktem.db.base_models as base_models
from ktem.db.engine import engine
from sqlmodel import SQLModel
from theflow.settings import settings
from theflow.utils.modules import import_dotted_string
_base_conv = (
import_dotted_string(settings.KH_TABLE_CONV, safe=False)
if hasattr(settings, "KH_TABLE_CONV")
else base_models.BaseConversation
)
_base_user = (
import_dotted_string(settings.KH_TABLE_USER, safe=False)
if hasattr(settings, "KH_TABLE_USER")
else base_models.BaseUser
)
_base_settings = (
import_dotted_string(settings.KH_TABLE_SETTINGS, safe=False)
if hasattr(settings, "KH_TABLE_SETTINGS")
else base_models.BaseSettings
)
_base_issue_report = (
import_dotted_string(settings.KH_TABLE_ISSUE_REPORT, safe=False)
if hasattr(settings, "KH_TABLE_ISSUE_REPORT")
else base_models.BaseIssueReport
)
class Conversation(_base_conv, table=True): # type: ignore
"""Conversation record"""
class User(_base_user, table=True): # type: ignore
"""User table"""
class Settings(_base_settings, table=True): # type: ignore
"""Record of settings"""
class IssueReport(_base_issue_report, table=True): # type: ignore
"""Record of issues"""
if not getattr(settings, "KH_ENABLE_ALEMBIC", False):
SQLModel.metadata.create_all(engine)