fix: db initialization and vector registration order
This commit is contained in:
14
server.py
14
server.py
@@ -18,11 +18,15 @@ EMBEDDING_DIM = 768 # BAAI/bge-base-en-v1.5
|
|||||||
mcp = FastMCP("knowledge-mcp")
|
mcp = FastMCP("knowledge-mcp")
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def get_db():
|
def get_db(init=False):
|
||||||
"""Provide a database connection."""
|
"""Provide a database connection."""
|
||||||
conn = psycopg.connect(DATABASE_URL, autocommit=True)
|
conn = psycopg.connect(DATABASE_URL, autocommit=True)
|
||||||
# Register vector type handler
|
# Register vector type handler (skip during init phase before extension exists)
|
||||||
|
if not init:
|
||||||
|
try:
|
||||||
register_vector(conn)
|
register_vector(conn)
|
||||||
|
except Exception as e:
|
||||||
|
logging.warning(f"Vector registration failed (ignoring if init): {e}")
|
||||||
try:
|
try:
|
||||||
yield conn
|
yield conn
|
||||||
finally:
|
finally:
|
||||||
@@ -31,9 +35,13 @@ def get_db():
|
|||||||
def init_db():
|
def init_db():
|
||||||
"""Initialize database schema."""
|
"""Initialize database schema."""
|
||||||
try:
|
try:
|
||||||
with get_db() as conn:
|
# Pass init=True to skip vector registration before extension exists
|
||||||
|
with get_db(init=True) as conn:
|
||||||
conn.execute("CREATE EXTENSION IF NOT EXISTS vector")
|
conn.execute("CREATE EXTENSION IF NOT EXISTS vector")
|
||||||
|
|
||||||
|
# Now we can register it for the rest of the session if we wanted,
|
||||||
|
# but for this function we just need to create tables.
|
||||||
|
|
||||||
# Notebooks table (simple registry)
|
# Notebooks table (simple registry)
|
||||||
conn.execute("""
|
conn.execute("""
|
||||||
CREATE TABLE IF NOT EXISTS notebooks (
|
CREATE TABLE IF NOT EXISTS notebooks (
|
||||||
|
|||||||
Reference in New Issue
Block a user