Merge pull request #2 from iamsyg/add-inference-params

feat: Add inference params
This commit is contained in:
Swayam Gupta 2025-10-05 16:23:04 +05:30 committed by GitHub
commit 3bc6dbfb5e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 193 additions and 2 deletions

View file

@ -0,0 +1,32 @@
"""add inference_params to searchspaces 2
Revision ID: 2c3ace3296c0
Revises: 9bc8b50514d0
Create Date: 2025-10-05 12:56:00.739719
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = '2c3ace3296c0'
down_revision: Union[str, None] = '9bc8b50514d0'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###

View file

@ -0,0 +1,46 @@
"""add inference_params to searchspaces
Revision ID: 4bad510c6eb4
Revises: 21
Create Date: 2025-10-05 10:19:08.790345
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision: str = '4bad510c6eb4'
down_revision: Union[str, None] = '21'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('chats', 'type',
existing_type=postgresql.ENUM('QNA', 'REPORT_GENERAL', 'REPORT_DEEP', 'REPORT_DEEPER', name='chattype'),
nullable=False)
op.drop_index(op.f('chucks_search_index'), table_name='chunks', postgresql_using='gin')
op.drop_index(op.f('chucks_vector_index'), table_name='chunks', postgresql_using='hnsw')
op.drop_index(op.f('document_search_index'), table_name='documents', postgresql_using='gin')
op.drop_index(op.f('document_vector_index'), table_name='documents', postgresql_using='hnsw')
op.add_column('searchspaces', sa.Column('inference_params', sa.JSON(), nullable=True))
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('searchspaces', 'inference_params')
op.create_index(op.f('document_vector_index'), 'documents', ['embedding'], unique=False, postgresql_using='hnsw')
op.create_index(op.f('document_search_index'), 'documents', [sa.literal_column("to_tsvector('english'::regconfig, content)")], unique=False, postgresql_using='gin')
op.create_index(op.f('chucks_vector_index'), 'chunks', ['embedding'], unique=False, postgresql_using='hnsw')
op.create_index(op.f('chucks_search_index'), 'chunks', [sa.literal_column("to_tsvector('english'::regconfig, content)")], unique=False, postgresql_using='gin')
op.alter_column('chats', 'type',
existing_type=postgresql.ENUM('QNA', 'REPORT_GENERAL', 'REPORT_DEEP', 'REPORT_DEEPER', name='chattype'),
nullable=True)
# ### end Alembic commands ###

View file

@ -0,0 +1,32 @@
"""add inference_params to searchspaces 1
Revision ID: 9bc8b50514d0
Revises: 4bad510c6eb4
Create Date: 2025-10-05 12:31:02.448057
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = '9bc8b50514d0'
down_revision: Union[str, None] = '4bad510c6eb4'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###

View file

@ -0,0 +1,38 @@
"""add inference_params to searchspaces 3
Revision ID: b86972495f7d
Revises: 2c3ace3296c0
Create Date: 2025-10-05 15:05:06.391825
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = 'b86972495f7d'
down_revision: Union[str, None] = '2c3ace3296c0'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('chucks_search_index'), table_name='chunks', postgresql_using='gin')
op.drop_index(op.f('chucks_vector_index'), table_name='chunks', postgresql_using='hnsw')
op.drop_index(op.f('document_search_index'), table_name='documents', postgresql_using='gin')
op.drop_index(op.f('document_vector_index'), table_name='documents', postgresql_using='hnsw')
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.create_index(op.f('document_vector_index'), 'documents', ['embedding'], unique=False, postgresql_using='hnsw')
op.create_index(op.f('document_search_index'), 'documents', [sa.literal_column("to_tsvector('english'::regconfig, content)")], unique=False, postgresql_using='gin')
op.create_index(op.f('chucks_vector_index'), 'chunks', ['embedding'], unique=False, postgresql_using='hnsw')
op.create_index(op.f('chucks_search_index'), 'chunks', [sa.literal_column("to_tsvector('english'::regconfig, content)")], unique=False, postgresql_using='gin')
# ### end Alembic commands ###

View file

@ -0,0 +1,32 @@
"""add inference_params to searchspaces 4
Revision ID: d17628273e13
Revises: b86972495f7d
Create Date: 2025-10-05 15:30:12.651638
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = 'd17628273e13'
down_revision: Union[str, None] = 'b86972495f7d'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###

View file

@ -204,6 +204,8 @@ class SearchSpace(BaseModel, TimestampMixin):
name = Column(String(100), nullable=False, index=True) name = Column(String(100), nullable=False, index=True)
description = Column(String(500), nullable=True) description = Column(String(500), nullable=True)
inference_params = Column(JSON, nullable=True)
user_id = Column( user_id = Column(
UUID(as_uuid=True), ForeignKey("user.id", ondelete="CASCADE"), nullable=False UUID(as_uuid=True), ForeignKey("user.id", ondelete="CASCADE"), nullable=False
) )

View file

@ -1,14 +1,21 @@
import uuid import uuid
from datetime import datetime from datetime import datetime
from pydantic import BaseModel, ConfigDict from pydantic import BaseModel, ConfigDict, Field
from .base import IDModel, TimestampModel from .base import IDModel, TimestampModel
class InferenceParams(BaseModel):
temperature: float | None = Field(None, ge=0.0, le=2.0)
max_tokens: int | None = Field(None, ge=0)
top_k: int | None = Field(None, ge=0)
top_p: float | None = Field(None, ge=0.0, le=1.0)
class SearchSpaceBase(BaseModel): class SearchSpaceBase(BaseModel):
name: str name: str
description: str | None = None description: str | None = None
inference_params: InferenceParams | None = None
class SearchSpaceCreate(SearchSpaceBase): class SearchSpaceCreate(SearchSpaceBase):
@ -16,7 +23,9 @@ class SearchSpaceCreate(SearchSpaceBase):
class SearchSpaceUpdate(SearchSpaceBase): class SearchSpaceUpdate(SearchSpaceBase):
pass name: str | None = None
description: str | None = None
inference_params: InferenceParams | None = None
class SearchSpaceRead(SearchSpaceBase, IDModel, TimestampModel): class SearchSpaceRead(SearchSpaceBase, IDModel, TimestampModel):