Fix Phase 1 server validation defects
This commit is contained in:
1 parent
55a2a41089
commit
a2ee7247d5
10 files changed
+114
-18
No files matched your search
@@ -2412,6 +2412,11 @@ def _ollama_embed(texts: list[str], model: str = OLLAMA_EMBED) -> list[list[floa
|
||||
log_context=f"_ollama_embed(model={model})", log_exc=e)
|
||||
return embeddings
|
||||
|
||||
def _chroma_collection_id(name: str) -> str:
|
||||
"""Resolve a stable Chroma collection name to the UUID required by data routes."""
|
||||
collection = _chroma_req("GET", f"/api/v1/collections/{name}")
|
||||
return collection["id"]
|
||||
|
||||
# Collections
|
||||
@app.get("/api/rag/collections")
|
||||
async def list_collections(admin: dict = Depends(admin_only)):
|
||||
@@ -2554,7 +2559,8 @@ async def delete_document(cid: int, doc_id: int, admin: dict = Depends(admin_onl
|
||||
# Remove chunks from ChromaDB
|
||||
if col:
|
||||
try:
|
||||
_chroma_req("POST", f"/api/v1/collections/{col['chroma_name']}/delete",
|
||||
chroma_id = _chroma_collection_id(col["chroma_name"])
|
||||
_chroma_req("POST", f"/api/v1/collections/{chroma_id}/delete",
|
||||
body={"where": {"doc_id": {"$eq": doc_id}}})
|
||||
except Exception:
|
||||
pass
|
||||
@@ -2598,7 +2604,8 @@ async def rag_query(body: dict, user: dict = Depends(current_user)):
|
||||
raise HTTPException(status_code=503, detail="Failed to embed query")
|
||||
|
||||
# Query ChromaDB
|
||||
result = _chroma_req("POST", f"/api/v1/collections/{col['chroma_name']}/query", body={
|
||||
chroma_id = _chroma_collection_id(col["chroma_name"])
|
||||
result = _chroma_req("POST", f"/api/v1/collections/{chroma_id}/query", body={
|
||||
"query_embeddings": embed,
|
||||
"n_results": n_results,
|
||||
"include": ["documents", "metadatas", "distances"]
|
||||
|
||||
Reference in new issue
Block a user