Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .docker/docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ services:
- CACHE_HEADER_TIME=0
- CACHE_TIME=0
- db_table=us_code_2025
- CHROMA_HOST=congress_chromadb
restart: unless-stopped
congress_viewer_app:
volumes:
Expand All @@ -27,6 +28,8 @@ services:
restart: unless-stopped
congress_postgres:
image: tianon/true
congress_chromadb:
restart: unless-stopped
networks:
parser:
external:
Expand Down
24 changes: 24 additions & 0 deletions .docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ services:
- db_user=parser
- db_pass=parser
- db_table=us_code_2025
- CHROMA_HOST=congress_chromadb
build:
context: ../backend
dockerfile: .docker/Dockerfile
Expand All @@ -48,6 +49,7 @@ services:
- "9091:8080"
depends_on:
- congress_postgres
- congress_chromadb
networks:
parser:
entrypoint: "uvicorn"
Expand Down Expand Up @@ -85,13 +87,16 @@ services:
container_name: congress_hillstack
tty: true
stdin_open: true
environment:
- FASTAPI_URL=http://congress_parser_fastapi:8080
build:
context: ../hillstack
dockerfile: .docker/Dockerfile
ports:
- "3001:3001"
depends_on:
- congress_postgres
- congress_parser_fastapi
networks:
parser:
congress_postgres:
Expand All @@ -107,9 +112,28 @@ services:
- postgres-volume:/var/lib/postgresql/data
networks:
parser:
congress_chromadb:
image: chromadb/chroma:0.6.3
container_name: congress_chromadb
environment:
- IS_PERSISTENT=TRUE
- PERSIST_DIRECTORY=/chroma/chroma
- ANONYMIZED_TELEMETRY=False
volumes:
- chromadb-volume:/chroma/chroma
ports:
- "8000:8000"
networks:
parser:
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/api/v1/heartbeat"]
interval: 30s
timeout: 10s
retries: 3
networks:
parser:
external:
name: docker_parser
volumes:
postgres-volume:
chromadb-volume:
107 changes: 107 additions & 0 deletions backend/.alembic/versions/a1b2c3d4e5f6_add_user_interest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
"""Add user_interest and user_interest_usc_content tables

Revision ID: a1b2c3d4e5f6
Revises: c9d7e37be069
Create Date: 2026-02-26 00:00:00.000000

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = 'a1b2c3d4e5f6'
down_revision: Union[str, None] = 'c9d7e37be069'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
op.create_table(
'user_interest',
sa.Column('user_interest_id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.String(), nullable=True),
sa.Column('interest_text', sa.String(), nullable=True),
sa.Column(
'created_at',
sa.DateTime(),
server_default=sa.text('now()'),
nullable=True,
),
sa.Column(
'updated_at',
sa.DateTime(),
server_default=sa.text('now()'),
nullable=True,
),
sa.ForeignKeyConstraint(
['user_id'],
['sensitive.user_ident.user_id'],
ondelete='CASCADE',
),
sa.PrimaryKeyConstraint('user_interest_id'),
schema='sensitive',
)
op.create_index(
'ix_sensitive_user_interest_user_id',
'user_interest',
['user_id'],
schema='sensitive',
)

op.create_table(
'user_interest_usc_content',
sa.Column('user_interest_usc_content_id', sa.Integer(), nullable=False),
sa.Column('user_interest_id', sa.Integer(), nullable=True),
sa.Column('usc_ident', sa.String(), nullable=True),
sa.Column('match_source', sa.String(), nullable=True),
sa.Column('is_active', sa.Boolean(), nullable=True, server_default=sa.text('true')),
sa.Column('match_rank', sa.Integer(), nullable=True),
sa.Column(
'created_at',
sa.DateTime(),
server_default=sa.text('now()'),
nullable=True,
),
sa.ForeignKeyConstraint(
['user_interest_id'],
['sensitive.user_interest.user_interest_id'],
ondelete='CASCADE',
),
sa.PrimaryKeyConstraint('user_interest_usc_content_id'),
schema='sensitive',
)
op.create_index(
'ix_sensitive_user_interest_usc_content_user_interest_id',
'user_interest_usc_content',
['user_interest_id'],
schema='sensitive',
)
op.create_index(
'ix_sensitive_user_interest_usc_content_usc_ident',
'user_interest_usc_content',
['usc_ident'],
schema='sensitive',
)


def downgrade() -> None:
op.drop_index(
'ix_sensitive_user_interest_usc_content_usc_ident',
table_name='user_interest_usc_content',
schema='sensitive',
)
op.drop_index(
'ix_sensitive_user_interest_usc_content_user_interest_id',
table_name='user_interest_usc_content',
schema='sensitive',
)
op.drop_table('user_interest_usc_content', schema='sensitive')
op.drop_index(
'ix_sensitive_user_interest_user_id',
table_name='user_interest',
schema='sensitive',
)
op.drop_table('user_interest', schema='sensitive')
43 changes: 43 additions & 0 deletions backend/congress_db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,49 @@ class UserUSCContent(SensitiveBase):
usc_ident = Column(String)


class UserInterest(SensitiveBase):
"""
Natural language interest statement for a user, used to auto-match USC sections
"""

__tablename__ = "user_interest"

user_interest_id = Column(Integer, primary_key=True)

user_id = Column(
String,
ForeignKey("sensitive.user_ident.user_id", ondelete="CASCADE"),
index=True,
)
interest_text = Column(String)
created_at = Column(DateTime, server_default=func.now())
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())


class UserInterestUscContent(SensitiveBase):
"""
USC content sections matched to a user's interest, either automatically or manually
"""

__tablename__ = "user_interest_usc_content"

user_interest_usc_content_id = Column(Integer, primary_key=True)

user_interest_id = Column(
Integer,
ForeignKey(
"sensitive.user_interest.user_interest_id",
ondelete="CASCADE",
),
index=True,
)
usc_ident = Column(String, index=True)
match_source = Column(String, default="auto") # 'auto' or 'manual'
is_active = Column(Boolean, default=True)
match_rank = Column(Integer, nullable=True)
created_at = Column(DateTime, server_default=func.now())


class UserLLMQuery(SensitiveBase):
"""
Acts as a log of all user queries into legislation, for tracking purposes
Expand Down
Loading