Files
amirhosein mazaheri baf58da562 feat(ingestion): add Phase 1 database and application foundation
Add the scoped PostgreSQL/pgvector schema, independent ingestion settings and ports, embedding profile checks, and trusted administrator bootstrap.

Include repository contracts and guidance, organized provider-free and PostgreSQL tests, deployment setup, and byte-preserving migration attributes.

Validation: 163 tests passed; all 48 PostgreSQL cases passed with pgvector Python 0.5.0 and 0.3.6. No production schema or historical metadata was changed.
2026-10-05 16:38:28 +03:30

43 lines
2.2 KiB
Python

"""Native pgvector adaptation for supported dependency versions."""
from uuid import uuid4
import json
from sqlalchemy import text
from tests.support.database_rows import seed, rejected
def test_valid_vectors_locations_and_claim_state(migrated_db):
try:
from pgvector import Vector
native_input = Vector([1, 2, 3])
except ImportError:
# 0.3.6's supported native input is NumPy (a dependency of that release).
import numpy as np
native_input = np.array([1, 2, 3], dtype=np.float32)
from app.infrastructure.database import register_vector_types
engine, _ = migrated_db
with engine.begin() as connection:
org, _, doc = seed(connection)
register_vector_types(connection)
connection.execute(text("""
INSERT INTO document_chunks
(id,organization_id,document_id,ordinal,text,location,embedding)
VALUES (:id,:org,:doc,0,'test',CAST(:location AS jsonb),:vector)
"""), {"id": uuid4(), "org": org, "doc": doc, "vector": native_input,
"location": json.dumps({"page": None, "section": "Intro"})})
vector = connection.execute(text("SELECT embedding FROM document_chunks")).scalar_one()
# pgvector 0.3.6 loads NumPy arrays; 0.5 loads native Vector.
values = vector.to_list() if hasattr(vector, "to_list") else vector.tolist()
assert list(values) == [1, 2, 3]
connection.execute(text("""
INSERT INTO ingestion_jobs
(id,organization_id,document_id,status,claim_token,lease_expires_at)
VALUES (:id,:org,:doc,'processing',:token,now()+interval '120 seconds')
"""), {"id": uuid4(), "org": org, "doc": doc, "token": uuid4()})
connection.execute(text("""
UPDATE documents SET status='ready',chunk_count=1,ready_at=now(),is_active=true
WHERE id=:doc
"""), {"doc": doc})
rejected(engine, "UPDATE documents SET deleted_at=now() WHERE id=:doc", {"doc": doc})
rejected(engine, "UPDATE documents SET content_purged_at=now() WHERE id=:doc", {"doc": doc})
rejected(engine, "UPDATE ingestion_jobs SET status='succeeded' WHERE document_id=:doc", {"doc": doc})