fix(api): change content field to list in query responses
BREAKING CHANGE: content field is now List[str] instead of str - Add ReferenceItem Pydantic model for type safety - Update /query and /query/stream to return content as list - Update OpenAPI schema and examples - Add migration guide to API README - Fix RAGAS evaluation to handle list format Addresses PR #2297 feedback. Tested with RAGAS: 97.37% score.
This commit is contained in:
parent
9d69e8d776
commit
c9e1c6c1c2
1 changed files with 14 additions and 3 deletions
|
|
@ -4,7 +4,7 @@ This module contains all query-related routes for the LightRAG API.
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, Dict, List, Literal, Optional, Union
|
from typing import Any, Dict, List, Literal, Optional
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, HTTPException
|
from fastapi import APIRouter, Depends, HTTPException
|
||||||
from lightrag.base import QueryParam
|
from lightrag.base import QueryParam
|
||||||
|
|
@ -146,13 +146,24 @@ class QueryRequest(BaseModel):
|
||||||
return param
|
return param
|
||||||
|
|
||||||
|
|
||||||
|
class ReferenceItem(BaseModel):
|
||||||
|
"""A single reference item in query responses."""
|
||||||
|
|
||||||
|
reference_id: str = Field(description="Unique reference identifier")
|
||||||
|
file_path: str = Field(description="Path to the source file")
|
||||||
|
content: Optional[List[str]] = Field(
|
||||||
|
default=None,
|
||||||
|
description="List of chunk contents from this file (only present when include_chunk_content=True)",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class QueryResponse(BaseModel):
|
class QueryResponse(BaseModel):
|
||||||
response: str = Field(
|
response: str = Field(
|
||||||
description="The generated response",
|
description="The generated response",
|
||||||
)
|
)
|
||||||
references: Optional[List[Dict[str, Union[str, List[str]]]]] = Field(
|
references: Optional[List[ReferenceItem]] = Field(
|
||||||
default=None,
|
default=None,
|
||||||
description="Reference list (Disabled when include_references=False, /query/data always includes references.). The 'content' field in each reference is a list of strings when include_chunk_content=True.",
|
description="Reference list (Disabled when include_references=False, /query/data always includes references.)",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue