Skip to content

Commit f82668a

Browse files
committed
docs: update the Swagger doc for the retrieval API
1 parent f07340c commit f82668a

1 file changed

Lines changed: 70 additions & 3 deletions

File tree

src/mmore/run_retriever.py

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,56 @@ def make_router(config_file: str) -> APIRouter:
140140
retriever_obj = Retriever.from_config(config)
141141
logger.info("Retriever loaded!")
142142

143-
@router.get("/list_files", tags=["Files"])
143+
@router.get(
144+
"/list_files",
145+
tags=["Files"],
146+
summary="List files in a collection",
147+
responses={
148+
200: {
149+
"description": "Files currently stored in the collection",
150+
"content": {
151+
"application/json": {
152+
"example": [
153+
{"id": "doc1", "filename": "report.pdf"},
154+
{"id": "doc2", "filename": "notes.md"},
155+
]
156+
}
157+
},
158+
},
159+
},
160+
)
144161
def list_files(
145162
collection_name: str, limit: int = Query(default=16000, ge=1, le=100000)
146163
):
147164
"""List all files currently in the database."""
148165
return retriever_obj.list_files(collection_name=collection_name, limit=limit)
149166

150-
@router.post("/v1/retrieve", tags=["Retrieval"])
167+
@router.post(
168+
"/v1/retrieve",
169+
tags=["Retrieval"],
170+
summary="Retrieve the most similar chunks for a query",
171+
responses={
172+
200: {
173+
"description": "Matching chunks ordered by similarity",
174+
"content": {
175+
"application/json": {
176+
"example": [
177+
{
178+
"fileId": "doc1",
179+
"chunkId": "3",
180+
"content": "the matched passage...",
181+
"similarity": 0.87,
182+
"metadata": {
183+
"first": {"page": 0, "paragraph": 2},
184+
"last": {"page": 0, "paragraph": 2},
185+
},
186+
}
187+
]
188+
}
189+
},
190+
},
191+
},
192+
)
151193
def retriever(query: RetrieverQuery):
152194
"""Query the retriever"""
153195

@@ -180,7 +222,32 @@ def retriever(query: RetrieverQuery):
180222

181223
return docs_info
182224

183-
@router.get("/v1/chunks/{fileId}/{chunkId}", tags=["Retrieval"])
225+
@router.get(
226+
"/v1/chunks/{fileId}/{chunkId}",
227+
tags=["Retrieval"],
228+
summary="Fetch a chunk's content and metadata by reference",
229+
responses={
230+
200: {
231+
"description": "Chunk content and positional metadata",
232+
"content": {
233+
"application/json": {
234+
"example": {
235+
"fileId": "doc1",
236+
"chunkId": "3",
237+
"filename": "report.pdf",
238+
"content": "the chunk text...",
239+
"metadata": {
240+
"first": {"page": 0, "paragraph": 2},
241+
"last": {"page": 1, "paragraph": 0},
242+
},
243+
}
244+
}
245+
},
246+
},
247+
400: {"description": "fileId or chunkId contains a forbidden character ('+' or '\"')"},
248+
404: {"description": "Chunk not found for the given file"},
249+
},
250+
)
184251
def get_chunk(fileId: str, chunkId: str):
185252
"""Fetch a chunk's content and positional metadata by reference."""
186253
if not _ID_PATTERN.match(fileId) or not _ID_PATTERN.match(chunkId):

0 commit comments

Comments
 (0)