.. | |||
README.md | 12 days ago | ||
__init__.py | 12 days ago | ||
database.py | 12 days ago | ||
models.py | 12 days ago |
Here is the properly formatted and organized version of your AI Model Hub Database Schema document:
This document provides a detailed overview of the PostgreSQL database schema for the AI Model Hub service, based on the SQLAlchemy models defined in app/db/model.py
. The schema supports core functionalities like:
The following diagram illustrates the relationships between the four main tables: sessions
, messages
, documents
, and vector_metadata
.
+-------------+ +-------------+ | sessions | <------ | messages | +-------------+ +-------------+ | id | 1 | id | | user_id | | session_id | | title | | sender | | model_name | | content | | created_at | | created_at | | is_archived | | model_response_time | +-------------+ | token_count | | metadata | +-------------+ ^ | 1 +------------------+ +-------------+ | vector_metadata | ---1:1--| documents | +------------------+ +-------------+ | id | | id | | document_id | | title | | faiss_index | | text | | session_id | | source_url | | embedding_model | | author | +------------------+ | status | | created_at | | user_id | +-------------+
sessions
TableStores metadata for each conversation session. Each row represents a single chat conversation.
id
(Integer, Primary Key): Unique session identifieruser_id
(String): ID of the session's owner. Indexed for quick lookupstitle
(String): Human-readable title for the sessionmodel_name
(String): LLM used (e.g., 'gemini-1.5-pro'
, 'deepseek-chat'
)created_at
(DateTime): Timestamp of session creationis_archived
(Boolean): Soft delete flagmessages
TableStores individual messages within a session.
id
(Integer, Primary Key): Unique message identifiersession_id
(Integer, Foreign Key): Links to sessions.id
sender
(String): Either 'user'
or 'assistant'
content
(Text): Message textcreated_at
(DateTime): Timestamp of messagemodel_response_time
(Integer): Time (in seconds) to generate responsetoken_count
(Integer): Tokens used for the messagemetadata
(JSON): Flexible field for model/tool-specific datadocuments
TableStores original text and metadata of documents ingested into the system.
id
(Integer, Primary Key): Unique document identifiertitle
(String): Document titletext
(Text): Full content of the documentsource_url
(String): URL or file path of originauthor
(String): Author of the documentstatus
(String): 'processing'
, 'ready'
, or 'failed'
created_at
(DateTime): Timestamp of uploaduser_id
(String): ID of the uploading uservector_metadata
TableLinks documents to their vector representations and session context for RAG.
id
(Integer, Primary Key): Unique metadata IDdocument_id
(Integer, Foreign Key): Links to documents.id
faiss_index
(Integer): Index in the FAISS vector storesession_id
(Integer, Foreign Key): Session where this vector was usedembedding_model
(String): Embedding model used (e.g., 'text-embedding-004'
)One-to-Many: sessions → messages
A session contains multiple messages; each message belongs to one session.
One-to-One: documents → vector_metadata
Each document has a single vector metadata record.
Many-to-One: vector_metadata → sessions
Multiple vector metadata entries can reference the same session if used for RAG.
Let me know if you’d like this in Markdown, PDF, or any specific format.