fix: 处理无pgvector扩展的PostgreSQL
This commit is contained in:
parent
38710b89ed
commit
3d62957fed
|
|
@ -4,14 +4,18 @@ import uuid
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from .database import Base
|
from .database import Base
|
||||||
|
|
||||||
# Compatibility layer for SQLite
|
# Compatibility layer for SQLite and PostgreSQL without pgvector
|
||||||
try:
|
try:
|
||||||
from sqlalchemy.dialects.postgresql import UUID, ARRAY
|
from sqlalchemy.dialects.postgresql import UUID, ARRAY
|
||||||
from pgvector.sqlalchemy import Vector
|
|
||||||
# Check if we are using SQLite
|
|
||||||
import os
|
import os
|
||||||
if "sqlite" in os.getenv("DATABASE_URL", ""):
|
if "sqlite" in os.getenv("DATABASE_URL", ""):
|
||||||
raise ImportError("Using SQLite")
|
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:
|
except ImportError:
|
||||||
from sqlalchemy.types import TypeDecorator, CHAR
|
from sqlalchemy.types import TypeDecorator, CHAR
|
||||||
import json
|
import json
|
||||||
|
|
@ -38,7 +42,6 @@ except ImportError:
|
||||||
if value is None: return None
|
if value is None: return None
|
||||||
return json.loads(value)
|
return json.loads(value)
|
||||||
|
|
||||||
# Use JSON for ARRAY in SQLite
|
|
||||||
ARRAY = JSON
|
ARRAY = JSON
|
||||||
|
|
||||||
class ContextNode(Base):
|
class ContextNode(Base):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue