fix(litellm-pgvector): honor caller-supplied id on vector store create

POST /v1/vector_stores always minted a random UUID for the new store's id,
ignoring the request entirely. litellm-config.yaml's vector_store_registry
addresses this store by a fixed id (memory-and-notes), which could never
match a real row as a result — every search/write 404'd.

Added an optional id field to VectorStoreCreateRequest; create_vector_store
uses it when given, falls back to a random UUID otherwise (unchanged
behavior for callers that don't care).
This commit is contained in:
2026-09-02 21:32:18 +00:00
parent b627edb949
commit 3eda4e3ec0
2 changed files with 17 additions and 3 deletions
+11 -3
View File
@@ -85,14 +85,22 @@ async def create_vector_store(
try: try:
# Use raw SQL to insert the vector store with configurable table/field names # Use raw SQL to insert the vector store with configurable table/field names
vector_store_table = settings.table_names["vector_stores"] vector_store_table = settings.table_names["vector_stores"]
# ponytail: honor a caller-supplied id (request.id) instead of
# always minting one — litellm's vector_store_registry addresses
# this store by a fixed id (see litellm-config.yaml), which never
# matched anything when this always generated a random UUID.
import uuid as _uuid
vector_store_id = request.id or str(_uuid.uuid4())
result = await db.query_raw( result = await db.query_raw(
f""" f"""
INSERT INTO {vector_store_table} (id, name, file_counts, status, usage_bytes, expires_after, metadata, created_at) INSERT INTO {vector_store_table} (id, name, file_counts, status, usage_bytes, expires_after, metadata, created_at)
VALUES (gen_random_uuid(), $1, $2, $3, $4, $5, $6, NOW()) VALUES ($1, $2, $3, $4, $5, $6, $7, NOW())
RETURNING id, name, file_counts, status, usage_bytes, expires_after, expires_at, last_active_at, metadata, RETURNING id, name, file_counts, status, usage_bytes, expires_after, expires_at, last_active_at, metadata,
EXTRACT(EPOCH FROM created_at)::bigint as created_at_timestamp EXTRACT(EPOCH FROM created_at)::bigint as created_at_timestamp
""", """,
vector_store_id,
request.name, request.name,
{"in_progress": 0, "completed": 0, "failed": 0, "cancelled": 0, "total": 0}, {"in_progress": 0, "completed": 0, "failed": 0, "cancelled": 0, "total": 0},
"completed", "completed",
+6
View File
@@ -5,6 +5,12 @@ from datetime import datetime
class VectorStoreCreateRequest(BaseModel): class VectorStoreCreateRequest(BaseModel):
name: str name: str
# ponytail: not part of upstream litellm-pgvector — added locally so
# callers (litellm's vector_store_registry, scripts/ingest-memory.sh)
# can pin a human-readable id instead of getting a random UUID back.
# litellm-config.yaml's vector_store_registry addresses stores by a
# fixed vector_store_id, which only works if creation can honor it.
id: Optional[str] = None
file_ids: Optional[List[str]] = None file_ids: Optional[List[str]] = None
expires_after: Optional[Dict[str, Any]] = None expires_after: Optional[Dict[str, Any]] = None
chunking_strategy: Optional[Dict[str, Any]] = None chunking_strategy: Optional[Dict[str, Any]] = None