feat(docs): add versioned document update and versions APIs
This commit is contained in:
@@ -1256,6 +1256,18 @@ class DocumentQueryRequest(BaseModel):
|
||||
limit: int = 5
|
||||
|
||||
|
||||
class DocumentUpdateRequest(BaseModel):
|
||||
"""Update existing document text and bump version."""
|
||||
agent_id: str
|
||||
doc_id: str
|
||||
file_name: Optional[str] = None
|
||||
text: str
|
||||
dao_id: Optional[str] = None
|
||||
user_id: Optional[str] = None
|
||||
storage_ref: Optional[str] = None
|
||||
metadata: Optional[Dict[str, Any]] = None
|
||||
|
||||
|
||||
class SharedMemoryReviewRequest(BaseModel):
|
||||
point_id: str
|
||||
approve: bool
|
||||
@@ -2976,6 +2988,7 @@ async def documents_query(request: DocumentQueryRequest):
|
||||
"doc_id": c_doc_id,
|
||||
"file_name": c_file,
|
||||
"chunk_index": c_idx,
|
||||
"version_no": ch.get("version_no"),
|
||||
"score": round(c_score, 4),
|
||||
}
|
||||
)
|
||||
@@ -3031,6 +3044,76 @@ async def documents_query(request: DocumentQueryRequest):
|
||||
}
|
||||
|
||||
|
||||
@app.post("/v1/documents/update")
|
||||
async def documents_update(request: DocumentUpdateRequest):
|
||||
"""
|
||||
Replace document chunks for doc_id with new text and create a new version row.
|
||||
"""
|
||||
if not MEMORY_RETRIEVAL_AVAILABLE or not memory_retrieval:
|
||||
raise HTTPException(status_code=503, detail="Memory retrieval not available")
|
||||
|
||||
agent_id = (request.agent_id or "").strip().lower()
|
||||
if not agent_id:
|
||||
raise HTTPException(status_code=400, detail="agent_id is required")
|
||||
|
||||
doc_id = (request.doc_id or "").strip()
|
||||
if not doc_id:
|
||||
raise HTTPException(status_code=400, detail="doc_id is required")
|
||||
|
||||
text = (request.text or "").strip()
|
||||
if not text:
|
||||
raise HTTPException(status_code=400, detail="text is required")
|
||||
|
||||
result = await memory_retrieval.update_document_chunks(
|
||||
agent_id=agent_id,
|
||||
doc_id=doc_id,
|
||||
file_name=request.file_name,
|
||||
text=text,
|
||||
dao_id=request.dao_id,
|
||||
user_id=request.user_id,
|
||||
metadata=request.metadata,
|
||||
storage_ref=request.storage_ref,
|
||||
)
|
||||
if not result.get("ok"):
|
||||
return {
|
||||
"ok": False,
|
||||
"error": result.get("error", "update_failed"),
|
||||
"doc_id": doc_id,
|
||||
"collection": result.get("collection"),
|
||||
}
|
||||
return result
|
||||
|
||||
|
||||
@app.get("/v1/documents/{doc_id}/versions")
|
||||
async def documents_versions(doc_id: str, agent_id: str, limit: int = 20):
|
||||
"""
|
||||
List stored versions for a document.
|
||||
"""
|
||||
if not MEMORY_RETRIEVAL_AVAILABLE or not memory_retrieval:
|
||||
raise HTTPException(status_code=503, detail="Memory retrieval not available")
|
||||
|
||||
aid = (agent_id or "").strip().lower()
|
||||
if not aid:
|
||||
raise HTTPException(status_code=400, detail="agent_id is required")
|
||||
|
||||
did = (doc_id or "").strip()
|
||||
if not did:
|
||||
raise HTTPException(status_code=400, detail="doc_id is required")
|
||||
|
||||
items = await memory_retrieval.list_document_versions(
|
||||
agent_id=aid,
|
||||
doc_id=did,
|
||||
limit=limit,
|
||||
)
|
||||
return {
|
||||
"ok": True,
|
||||
"agent_id": aid,
|
||||
"doc_id": did,
|
||||
"total": len(items),
|
||||
"items": items,
|
||||
}
|
||||
|
||||
|
||||
@app.get("/v1/models")
|
||||
async def list_available_models():
|
||||
"""List all available models across backends"""
|
||||
|
||||
Reference in New Issue
Block a user