Skip to content

Commit 149d1e9

Browse files
authored
Make GraphRAG search's query backwards compatible (#97)
* Make query backwards compatible * Update CHANGELOG
1 parent b4cde39 commit 149d1e9

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

CHANGELOG.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44

55
### Added
66
- Add optional custom_prompt arg to the Text2CypherRetriever class.
7-
7+
8+
### Changed
9+
- `GraphRAG.search` method first parameter has been renamed `query_text` (was `query`) for consistency with the retrievers interface.
10+
- Made `GraphRAG.search` method backwards compatible with the query parameter, raising warnings to encourage using query_text instead.
11+
812
## 0.3.1
913

1014
### Fixed
1115
- Corrected initialization to allow specifying the embedding model name.
1216
- Removed sentence_transformers from embeddings/__init__.py to avoid ImportError when the package is not installed.
1317

14-
### Changed
15-
- `GraphRAG.search` method first parameter has been renamed `query_text` (was `query`) for consistency with the retrievers interface.
16-
1718
## 0.3.0
1819

1920
### Added

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ rag = GraphRAG(retriever=retriever, llm=llm)
128128

129129
# Query the graph
130130
query_text = "How do I do similarity search in Neo4j?"
131-
response = rag.search(query=query_text, retriever_config={"top_k": 5})
131+
response = rag.search(query_text=query_text, retriever_config={"top_k": 5})
132132
print(response.answer)
133133
```
134134

src/neo4j_genai/generation/graphrag.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from __future__ import annotations
1616

1717
import logging
18+
import warnings
1819
from typing import Any, Optional
1920

2021
from pydantic import ValidationError
@@ -53,10 +54,11 @@ def __init__(
5354

5455
def search(
5556
self,
56-
query_text: str,
57+
query_text: str = "",
5758
examples: str = "",
5859
retriever_config: Optional[dict[str, Any]] = None,
5960
return_context: bool = False,
61+
query: Optional[str] = None,
6062
) -> RagResultModel:
6163
"""This method performs a full RAG search:
6264
1. Retrieval: context retrieval
@@ -69,12 +71,28 @@ def search(
6971
retriever_config (Optional[dict]): Parameters passed to the retriever
7072
search method; e.g.: top_k
7173
return_context (bool): Whether to return the retriever result (default: False)
74+
query (Optional[str]): The user question. Will be deprecated in favor of query_text.
7275
7376
Returns:
7477
RagResultModel: The LLM-generated answer
7578
7679
"""
7780
try:
81+
if query is not None:
82+
if query_text:
83+
warnings.warn(
84+
"Both 'query' and 'query_text' are provided, 'query_text' will be used.",
85+
DeprecationWarning,
86+
stacklevel=2,
87+
)
88+
elif isinstance(query, str):
89+
warnings.warn(
90+
"'query' is deprecated and will be removed in a future version, please use 'query_text' instead.",
91+
DeprecationWarning,
92+
stacklevel=2,
93+
)
94+
query_text = query
95+
7896
validated_data = RagSearchModel(
7997
query_text=query_text,
8098
examples=examples,

0 commit comments

Comments
 (0)