fix: 处理无pgvector扩展的PostgreSQL

This commit is contained in:
Sens 2026-02-21 01:40:13 +08:00
parent 38710b89ed
commit 3d62957fed
1 changed files with 7 additions and 4 deletions

View File

@ -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):