From 3d62957fed68a77e0d3ce0335a4f714d0a673b51 Mon Sep 17 00:00:00 2001 From: lgh <625458956@qq.com> Date: Sat, 21 Feb 2026 01:40:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A4=84=E7=90=86=E6=97=A0pgvector?= =?UTF-8?q?=E6=89=A9=E5=B1=95=E7=9A=84PostgreSQL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/models.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/backend/app/models.py b/backend/app/models.py index dbdbf09..c33af44 100644 --- a/backend/app/models.py +++ b/backend/app/models.py @@ -4,14 +4,18 @@ import uuid from datetime import datetime from .database import Base -# Compatibility layer for SQLite +# Compatibility layer for SQLite and PostgreSQL without pgvector try: from sqlalchemy.dialects.postgresql import UUID, ARRAY - from pgvector.sqlalchemy import Vector - # Check if we are using SQLite import os if "sqlite" in os.getenv("DATABASE_URL", ""): raise ImportError("Using SQLite") + # Try to import pgvector, if fails use JSON + try: + from pgvector.sqlalchemy import Vector + except ImportError: + # No pgvector, use JSON instead + Vector = JSON except ImportError: from sqlalchemy.types import TypeDecorator, CHAR import json @@ -38,7 +42,6 @@ except ImportError: if value is None: return None return json.loads(value) - # Use JSON for ARRAY in SQLite ARRAY = JSON class ContextNode(Base):