diff --git a/lightrag/lightrag.py b/lightrag/lightrag.py index a5cb3b22..48b464a8 100644 --- a/lightrag/lightrag.py +++ b/lightrag/lightrag.py @@ -1294,14 +1294,14 @@ class LightRAG: ): """ Query with separate keyword extraction step. - + This method extracts keywords from the query first, then uses them for the query. - + Args: query: User query prompt: Additional prompt for the query param: Query parameters - + Returns: Query response """ @@ -1315,12 +1315,12 @@ class LightRAG: ) -> str | AsyncIterator[str]: """ Async version of query_with_separate_keyword_extraction. - + Args: query: User query prompt: Additional prompt for the query param: Query parameters - + Returns: Query response or async iterator """ @@ -1336,7 +1336,7 @@ class LightRAG: global_config=asdict(self), hashing_kv=self.llm_response_cache, ) - + await self._query_done() return response diff --git a/lightrag/operate.py b/lightrag/operate.py index 95a5c72e..1815f308 100644 --- a/lightrag/operate.py +++ b/lightrag/operate.py @@ -1917,6 +1917,7 @@ async def kg_query_with_keywords( return response + async def query_with_keywords( query: str, prompt: str, @@ -1931,11 +1932,11 @@ async def query_with_keywords( ) -> str | AsyncIterator[str]: """ Extract keywords from the query and then use them for retrieving information. - + 1. Extracts high-level and low-level keywords from the query 2. Formats the query with the extracted keywords and prompt 3. Uses the appropriate query method based on param.mode - + Args: query: The user's query prompt: Additional prompt to prepend to the query @@ -1947,7 +1948,7 @@ async def query_with_keywords( text_chunks_db: Text chunks storage global_config: Global configuration hashing_kv: Cache storage - + Returns: Query response or async iterator """ diff --git a/lightrag/utils.py b/lightrag/utils.py index 1143b326..b8f00c5d 100644 --- a/lightrag/utils.py +++ b/lightrag/utils.py @@ -891,6 +891,7 @@ def lazy_external_import(module_name: str, class_name: str) -> Callable[..., Any return import_class + def get_content_summary(content: str, max_length: int = 100) -> str: """Get summary of document content @@ -906,6 +907,7 @@ def get_content_summary(content: str, max_length: int = 100) -> str: return content return content[:max_length] + "..." + def clean_text(text: str) -> str: """Clean text by removing null bytes (0x00) and whitespace @@ -917,6 +919,7 @@ def clean_text(text: str) -> str: """ return text.strip().replace("\x00", "") + def check_storage_env_vars(storage_name: str) -> None: """Check if all required environment variables for storage implementation exist @@ -927,7 +930,7 @@ def check_storage_env_vars(storage_name: str) -> None: ValueError: If required environment variables are missing """ from lightrag.kg import STORAGE_ENV_REQUIREMENTS - + required_vars = STORAGE_ENV_REQUIREMENTS.get(storage_name, []) missing_vars = [var for var in required_vars if var not in os.environ] @@ -935,4 +938,4 @@ def check_storage_env_vars(storage_name: str) -> None: raise ValueError( f"Storage implementation '{storage_name}' requires the following " f"environment variables: {', '.join(missing_vars)}" - ) \ No newline at end of file + )