Skip to content

Commit 9394cf9

Browse files
authored
fix: doc build and lint files (#34)
* fix doc build * fix doc build
1 parent 47be07f commit 9394cf9

124 files changed

Lines changed: 5561 additions & 5294 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

hindsight-api/hindsight_api/__init__.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,24 @@
33
44
Temporal + Semantic Memory Architecture using PostgreSQL with pgvector.
55
"""
6+
7+
from .config import HindsightConfig, get_config
8+
from .engine.cross_encoder import CrossEncoderModel, LocalSTCrossEncoder, RemoteTEICrossEncoder
9+
from .engine.embeddings import Embeddings, LocalSTEmbeddings, RemoteTEIEmbeddings
10+
from .engine.llm_wrapper import LLMConfig
611
from .engine.memory_engine import MemoryEngine
712
from .engine.search.trace import (
8-
SearchTrace,
9-
QueryInfo,
1013
EntryPoint,
11-
NodeVisit,
12-
WeightComponents,
1314
LinkInfo,
15+
NodeVisit,
1416
PruningDecision,
15-
SearchSummary,
17+
QueryInfo,
1618
SearchPhaseMetrics,
19+
SearchSummary,
20+
SearchTrace,
21+
WeightComponents,
1722
)
1823
from .engine.search.tracer import SearchTracer
19-
from .engine.embeddings import Embeddings, LocalSTEmbeddings, RemoteTEIEmbeddings
20-
from .engine.cross_encoder import CrossEncoderModel, LocalSTCrossEncoder, RemoteTEICrossEncoder
21-
from .engine.llm_wrapper import LLMConfig
22-
from .config import HindsightConfig, get_config
2324

2425
__all__ = [
2526
"MemoryEngine",

hindsight-api/hindsight_api/alembic/env.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,19 @@
22
Alembic environment configuration for SQLAlchemy with pgvector.
33
Uses synchronous psycopg2 driver for migrations to avoid pgbouncer issues.
44
"""
5+
56
import logging
67
import os
7-
import sys
88
from pathlib import Path
99

10-
from sqlalchemy import pool, engine_from_config
11-
from sqlalchemy.engine import Connection
12-
1310
from alembic import context
1411
from dotenv import load_dotenv
12+
from sqlalchemy import engine_from_config, pool
1513

1614
# Import your models here
1715
from hindsight_api.models import Base
1816

17+
1918
# Load environment variables based on HINDSIGHT_API_DATABASE_URL env var or default to local
2019
def load_env():
2120
"""Load environment variables from .env"""
@@ -30,6 +29,7 @@ def load_env():
3029
if env_file.exists():
3130
load_dotenv(env_file)
3231

32+
3333
load_env()
3434

3535
# this is the Alembic Config object, which provides
@@ -128,10 +128,7 @@ def set_read_write_mode(dbapi_connection, connection_record):
128128
connection.execute(text("SET SESSION CHARACTERISTICS AS TRANSACTION READ WRITE"))
129129
connection.commit() # Commit the SET command
130130

131-
context.configure(
132-
connection=connection,
133-
target_metadata=target_metadata
134-
)
131+
context.configure(connection=connection, target_metadata=target_metadata)
135132

136133
with context.begin_transaction():
137134
context.run_migrations()

hindsight-api/hindsight_api/alembic/versions/5a366d414dce_initial_schema.py

Lines changed: 266 additions & 180 deletions
Large diffs are not rendered by default.

hindsight-api/hindsight_api/alembic/versions/b7c4d8e9f1a2_add_chunks_table.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,66 +5,66 @@
55
Create Date: 2025-11-28 00:00:00.000000
66
77
"""
8-
from typing import Sequence, Union
98

10-
from alembic import op
9+
from collections.abc import Sequence
10+
1111
import sqlalchemy as sa
12+
from alembic import op
1213
from sqlalchemy.dialects import postgresql
1314

14-
1515
# revision identifiers, used by Alembic.
16-
revision: str = 'b7c4d8e9f1a2'
17-
down_revision: Union[str, Sequence[str], None] = '5a366d414dce'
18-
branch_labels: Union[str, Sequence[str], None] = None
19-
depends_on: Union[str, Sequence[str], None] = None
16+
revision: str = "b7c4d8e9f1a2"
17+
down_revision: str | Sequence[str] | None = "5a366d414dce"
18+
branch_labels: str | Sequence[str] | None = None
19+
depends_on: str | Sequence[str] | None = None
2020

2121

2222
def upgrade() -> None:
2323
"""Add chunks table and link memory_units to chunks."""
2424

2525
# Create chunks table with single text PK (bank_id_document_id_chunk_index)
2626
op.create_table(
27-
'chunks',
28-
sa.Column('chunk_id', sa.Text(), nullable=False),
29-
sa.Column('document_id', sa.Text(), nullable=False),
30-
sa.Column('bank_id', sa.Text(), nullable=False),
31-
sa.Column('chunk_index', sa.Integer(), nullable=False),
32-
sa.Column('chunk_text', sa.Text(), nullable=False),
33-
sa.Column('created_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
34-
sa.ForeignKeyConstraint(['document_id', 'bank_id'], ['documents.id', 'documents.bank_id'], name='chunks_document_fkey', ondelete='CASCADE'),
35-
sa.PrimaryKeyConstraint('chunk_id', name=op.f('pk_chunks'))
27+
"chunks",
28+
sa.Column("chunk_id", sa.Text(), nullable=False),
29+
sa.Column("document_id", sa.Text(), nullable=False),
30+
sa.Column("bank_id", sa.Text(), nullable=False),
31+
sa.Column("chunk_index", sa.Integer(), nullable=False),
32+
sa.Column("chunk_text", sa.Text(), nullable=False),
33+
sa.Column("created_at", postgresql.TIMESTAMP(timezone=True), server_default=sa.text("now()"), nullable=False),
34+
sa.ForeignKeyConstraint(
35+
["document_id", "bank_id"],
36+
["documents.id", "documents.bank_id"],
37+
name="chunks_document_fkey",
38+
ondelete="CASCADE",
39+
),
40+
sa.PrimaryKeyConstraint("chunk_id", name=op.f("pk_chunks")),
3641
)
3742

3843
# Add indexes for efficient queries
39-
op.create_index('idx_chunks_document_id', 'chunks', ['document_id'])
40-
op.create_index('idx_chunks_bank_id', 'chunks', ['bank_id'])
44+
op.create_index("idx_chunks_document_id", "chunks", ["document_id"])
45+
op.create_index("idx_chunks_bank_id", "chunks", ["bank_id"])
4146

4247
# Add chunk_id column to memory_units (nullable, as existing records won't have chunks)
43-
op.add_column('memory_units', sa.Column('chunk_id', sa.Text(), nullable=True))
48+
op.add_column("memory_units", sa.Column("chunk_id", sa.Text(), nullable=True))
4449

4550
# Add foreign key constraint to chunks table
4651
op.create_foreign_key(
47-
'memory_units_chunk_fkey',
48-
'memory_units',
49-
'chunks',
50-
['chunk_id'],
51-
['chunk_id'],
52-
ondelete='SET NULL'
52+
"memory_units_chunk_fkey", "memory_units", "chunks", ["chunk_id"], ["chunk_id"], ondelete="SET NULL"
5353
)
5454

5555
# Add index on chunk_id for efficient lookups
56-
op.create_index('idx_memory_units_chunk_id', 'memory_units', ['chunk_id'])
56+
op.create_index("idx_memory_units_chunk_id", "memory_units", ["chunk_id"])
5757

5858

5959
def downgrade() -> None:
6060
"""Remove chunks table and chunk_id from memory_units."""
6161

6262
# Drop index and foreign key from memory_units
63-
op.drop_index('idx_memory_units_chunk_id', table_name='memory_units')
64-
op.drop_constraint('memory_units_chunk_fkey', 'memory_units', type_='foreignkey')
65-
op.drop_column('memory_units', 'chunk_id')
63+
op.drop_index("idx_memory_units_chunk_id", table_name="memory_units")
64+
op.drop_constraint("memory_units_chunk_fkey", "memory_units", type_="foreignkey")
65+
op.drop_column("memory_units", "chunk_id")
6666

6767
# Drop chunks table indexes and table
68-
op.drop_index('idx_chunks_bank_id', table_name='chunks')
69-
op.drop_index('idx_chunks_document_id', table_name='chunks')
70-
op.drop_table('chunks')
68+
op.drop_index("idx_chunks_bank_id", table_name="chunks")
69+
op.drop_index("idx_chunks_document_id", table_name="chunks")
70+
op.drop_table("chunks")

hindsight-api/hindsight_api/alembic/versions/c8e5f2a3b4d1_add_retain_params_to_documents.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,35 @@
55
Create Date: 2025-12-02 00:00:00.000000
66
77
"""
8-
from typing import Sequence, Union
98

10-
from alembic import op
9+
from collections.abc import Sequence
10+
1111
import sqlalchemy as sa
12+
from alembic import op
1213
from sqlalchemy.dialects import postgresql
1314

14-
1515
# revision identifiers, used by Alembic.
16-
revision: str = 'c8e5f2a3b4d1'
17-
down_revision: Union[str, Sequence[str], None] = 'b7c4d8e9f1a2'
18-
branch_labels: Union[str, Sequence[str], None] = None
19-
depends_on: Union[str, Sequence[str], None] = None
16+
revision: str = "c8e5f2a3b4d1"
17+
down_revision: str | Sequence[str] | None = "b7c4d8e9f1a2"
18+
branch_labels: str | Sequence[str] | None = None
19+
depends_on: str | Sequence[str] | None = None
2020

2121

2222
def upgrade() -> None:
2323
"""Add retain_params JSONB column to documents table."""
2424

2525
# Add retain_params column to store parameters passed during retain
26-
op.add_column('documents', sa.Column('retain_params', postgresql.JSONB(), nullable=True))
26+
op.add_column("documents", sa.Column("retain_params", postgresql.JSONB(), nullable=True))
2727

2828
# Add index for efficient queries on retain_params
29-
op.create_index('idx_documents_retain_params', 'documents', ['retain_params'], postgresql_using='gin')
29+
op.create_index("idx_documents_retain_params", "documents", ["retain_params"], postgresql_using="gin")
3030

3131

3232
def downgrade() -> None:
3333
"""Remove retain_params column from documents table."""
3434

3535
# Drop index
36-
op.drop_index('idx_documents_retain_params', table_name='documents')
36+
op.drop_index("idx_documents_retain_params", table_name="documents")
3737

3838
# Drop column
39-
op.drop_column('documents', 'retain_params')
39+
op.drop_column("documents", "retain_params")

hindsight-api/hindsight_api/alembic/versions/d9f6a3b4c5e2_rename_bank_to_interactions.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,19 @@
55
Create Date: 2024-12-04 15:00:00.000000
66
77
"""
8-
from alembic import op
9-
import sqlalchemy as sa
108

9+
from alembic import op
1110

1211
# revision identifiers, used by Alembic.
13-
revision = 'd9f6a3b4c5e2'
14-
down_revision = 'c8e5f2a3b4d1'
12+
revision = "d9f6a3b4c5e2"
13+
down_revision = "c8e5f2a3b4d1"
1514
branch_labels = None
1615
depends_on = None
1716

1817

1918
def upgrade():
2019
# Drop old check constraint FIRST (before updating data)
21-
op.drop_constraint('memory_units_fact_type_check', 'memory_units', type_='check')
20+
op.drop_constraint("memory_units_fact_type_check", "memory_units", type_="check")
2221

2322
# Update existing 'bank' values to 'experience'
2423
op.execute("UPDATE memory_units SET fact_type = 'experience' WHERE fact_type = 'bank'")
@@ -27,22 +26,18 @@ def upgrade():
2726

2827
# Create new check constraint with 'experience' instead of 'bank'
2928
op.create_check_constraint(
30-
'memory_units_fact_type_check',
31-
'memory_units',
32-
"fact_type IN ('world', 'experience', 'opinion', 'observation')"
29+
"memory_units_fact_type_check", "memory_units", "fact_type IN ('world', 'experience', 'opinion', 'observation')"
3330
)
3431

3532

3633
def downgrade():
3734
# Drop new check constraint FIRST
38-
op.drop_constraint('memory_units_fact_type_check', 'memory_units', type_='check')
35+
op.drop_constraint("memory_units_fact_type_check", "memory_units", type_="check")
3936

4037
# Update 'experience' back to 'bank'
4138
op.execute("UPDATE memory_units SET fact_type = 'bank' WHERE fact_type = 'experience'")
4239

4340
# Recreate old check constraint
4441
op.create_check_constraint(
45-
'memory_units_fact_type_check',
46-
'memory_units',
47-
"fact_type IN ('world', 'bank', 'opinion', 'observation')"
42+
"memory_units_fact_type_check", "memory_units", "fact_type IN ('world', 'bank', 'opinion', 'observation')"
4843
)

hindsight-api/hindsight_api/alembic/versions/e0a1b2c3d4e5_disposition_to_3_traits.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88
agreeableness, neuroticism, bias_strength with 0-1 float values) to the new 3-trait
99
system (skepticism, literalism, empathy with 1-5 integer values).
1010
"""
11-
from typing import Sequence, Union
1211

13-
from alembic import op
14-
import sqlalchemy as sa
12+
from collections.abc import Sequence
1513

14+
import sqlalchemy as sa
15+
from alembic import op
1616

1717
# revision identifiers, used by Alembic.
18-
revision: str = 'e0a1b2c3d4e5'
19-
down_revision: Union[str, Sequence[str], None] = 'rename_personality'
20-
branch_labels: Union[str, Sequence[str], None] = None
21-
depends_on: Union[str, Sequence[str], None] = None
18+
revision: str = "e0a1b2c3d4e5"
19+
down_revision: str | Sequence[str] | None = "rename_personality"
20+
branch_labels: str | Sequence[str] | None = None
21+
depends_on: str | Sequence[str] | None = None
2222

2323

2424
def upgrade() -> None:
@@ -31,32 +31,40 @@ def upgrade() -> None:
3131
# - literalism: derived from conscientiousness (detail-oriented people are more literal)
3232
# - empathy: derived from agreeableness + inverse of neuroticism
3333
# Default all to 3 (neutral) for simplicity
34-
conn.execute(sa.text("""
34+
conn.execute(
35+
sa.text("""
3536
UPDATE banks
3637
SET disposition = '{"skepticism": 3, "literalism": 3, "empathy": 3}'::jsonb
3738
WHERE disposition IS NOT NULL
38-
"""))
39+
""")
40+
)
3941

4042
# Update the default for new banks
41-
conn.execute(sa.text("""
43+
conn.execute(
44+
sa.text("""
4245
ALTER TABLE banks
4346
ALTER COLUMN disposition SET DEFAULT '{"skepticism": 3, "literalism": 3, "empathy": 3}'::jsonb
44-
"""))
47+
""")
48+
)
4549

4650

4751
def downgrade() -> None:
4852
"""Convert back to Big Five disposition."""
4953
conn = op.get_bind()
5054

5155
# Revert to Big Five format with default values
52-
conn.execute(sa.text("""
56+
conn.execute(
57+
sa.text("""
5358
UPDATE banks
5459
SET disposition = '{"openness": 0.5, "conscientiousness": 0.5, "extraversion": 0.5, "agreeableness": 0.5, "neuroticism": 0.5, "bias_strength": 0.5}'::jsonb
5560
WHERE disposition IS NOT NULL
56-
"""))
61+
""")
62+
)
5763

5864
# Update the default for new banks
59-
conn.execute(sa.text("""
65+
conn.execute(
66+
sa.text("""
6067
ALTER TABLE banks
6168
ALTER COLUMN disposition SET DEFAULT '{"openness": 0.5, "conscientiousness": 0.5, "extraversion": 0.5, "agreeableness": 0.5, "neuroticism": 0.5, "bias_strength": 0.5}'::jsonb
62-
"""))
69+
""")
70+
)

0 commit comments

Comments
 (0)