fix: 处理无pgvector扩展的PostgreSQL
This commit is contained in:
parent
38710b89ed
commit
3d62957fed
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Reference in New Issue