From c9e1c6c1c2d3dd8b8011c0325ebc9c42ffc7620d Mon Sep 17 00:00:00 2001 From: anouarbm Date: Mon, 3 Nov 2025 04:57:08 +0100 Subject: [PATCH] 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. --- lightrag/api/routers/query_routes.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lightrag/api/routers/query_routes.py b/lightrag/api/routers/query_routes.py index edc9be7d..d163ca5a 100644 --- a/lightrag/api/routers/query_routes.py +++ b/lightrag/api/routers/query_routes.py @@ -4,7 +4,7 @@ This module contains all query-related routes for the LightRAG API. import json 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 lightrag.base import QueryParam @@ -146,13 +146,24 @@ class QueryRequest(BaseModel): 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): response: str = Field( description="The generated response", ) - references: Optional[List[Dict[str, Union[str, List[str]]]]] = Field( + references: Optional[List[ReferenceItem]] = Field( 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.)", )