Skip to content

Commit 249bcc2

Browse files
authored
DAGE-116: Rename doc_number to number_of_docs (#256)
1 parent 4977789 commit 249bcc2

26 files changed

Lines changed: 69 additions & 65 deletions

rre-tools/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ uv sync
4545
uv sync --group dev
4646
```
4747

48+
# remove all cached packages
49+
uv cache clean
50+
```
51+
4852
## Running Dataset Generator
4953
5054
Before running the command below, you need to have running search engine instance

rre-tools/configs/dataset_generator/dataset_generator_config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ search_engine_url: "http://localhost:8983/solr/"
2727
# - "book"
2828

2929
# Maximum number of documents to retrieve from the search engine to generate queries
30-
doc_number: 2
30+
number_of_docs: 2
3131

3232
# List of fields from documents used to generate queries and relevance scoring
3333
# These should match fields available in the search engine schema

rre-tools/docs/dataset_generator/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ one fields, the documents are filtered for both fields (AND-like)
2727
> - "fantasy"
2828
> - type:
2929
> - "book"
30-
> - **doc_number**: Maximum number of documents to retrieve from the search engine to generate queries (e.g. 100)
30+
> - **number_of_docs**: Maximum number of documents to retrieve from the search engine to generate queries (e.g. 100)
3131
> - **doc_fields**: List of fields from documents used to generate queries and relevance scoring. These should match
3232
> fields available in the search engine schema and must be at least one field
3333
> - an example could be:

rre-tools/src/rre_tools/dataset_generator/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Config(BaseModel):
2323
None,
2424
description="Optional list of filter conditions for documents"
2525
)
26-
doc_number: int = Field(..., gt=0, description="Number of documents to retrieve from the search engine.")
26+
number_of_docs: int = Field(..., gt=0, description="Number of documents to retrieve from the search engine.")
2727
doc_fields: List[str] = Field(..., min_length=1, description="Fields used for context and scoring.")
2828
queries: Optional[FilePath] = Field(None, description="Optional file containing predefined queries.")
2929
generate_queries_from_documents: Optional[bool] = True

rre-tools/src/rre_tools/dataset_generator/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def generate_and_add_queries(config: Config, data_store: DataStore, llm_service:
5656
"""Retrieve docs and generate queries with LLM Service. Adds docs, queries and ratings to the datastore."""
5757
docs_to_generate_queries: List[Document] = search_engine.fetch_for_query_generation(
5858
documents_filter=config.documents_filter,
59-
doc_number=config.doc_number,
59+
number_of_docs=config.number_of_docs,
6060
doc_fields=config.doc_fields
6161
)
6262

@@ -68,7 +68,7 @@ def generate_and_add_queries(config: Config, data_store: DataStore, llm_service:
6868
if remaining == 0:
6969
return
7070

71-
num_queries_per_doc: int = int( (remaining // max(1, config.doc_number)) + 1) # always greater or equal to 1
71+
num_queries_per_doc: int = int((remaining // max(1, config.number_of_docs)) + 1) # always greater or equal to 1
7272
log.debug(f"Number of documents retrieved for generation: {len(docs_to_generate_queries)}")
7373
log.debug(f"Pending queries to generate: {remaining}")
7474
log.debug(f"Number of queries per document: {num_queries_per_doc}")

rre-tools/src/rre_tools/shared/search_engines/elasticsearch_search_engine.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def _fetch_all_payload(self) -> Dict[str, Any]:
4646

4747
def fetch_for_query_generation(self,
4848
documents_filter: Union[None, List[Dict[str, List[str]]]],
49-
doc_number: int,
49+
number_of_docs: int,
5050
doc_fields: List[str],
5151
start: int = 0) -> List[Document]:
5252
"""
@@ -55,7 +55,7 @@ def fetch_for_query_generation(self,
5555
Args:
5656
documents_filter (Union[None, List[Dict[str, List[str]]]]): Optional list of field filters to apply.
5757
Each filter is a dictionary mapping field names to allowed values.
58-
doc_number (int): Number of documents to retrieve.
58+
number_of_docs (int): Number of documents to retrieve.
5959
doc_fields (List[str]): List of field names to include in the output.
6060
start (int, optional): Starting index. Defaults to 0.
6161
@@ -85,7 +85,7 @@ def fetch_for_query_generation(self,
8585

8686
# Construct the payload (Elasticsearch query body)
8787
payload = {
88-
"size": doc_number,
88+
"size": number_of_docs,
8989
"query": query,
9090
"from": start,
9191
"_source": doc_fields

rre-tools/src/rre_tools/shared/search_engines/opensearch_engine.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def _fetch_all_payload(self) -> Dict[str, Any]:
4444

4545
def fetch_for_query_generation(self,
4646
documents_filter: Union[None, List[Dict[str, List[str]]]],
47-
doc_number: int,
47+
number_of_docs: int,
4848
doc_fields: List[str],
4949
start: int = 0) -> List[Document]:
5050
"""Fetches a list of documents for query generation based on optional filters."""
@@ -75,7 +75,7 @@ def fetch_for_query_generation(self,
7575
"query": query,
7676
"_source": fields,
7777
"from": start,
78-
"size": doc_number
78+
"size": number_of_docs
7979
}
8080

8181
return self._search(payload)

rre-tools/src/rre_tools/shared/search_engines/search_engine_base.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from pydantic import HttpUrl
77
from rre_tools.shared.models.document import Document
88

9-
DOC_NUMBER_EACH_FETCH = 100
9+
NUMBER_OF_DOCS_EACH_FETCH = 100
1010

1111
class BaseSearchEngine(ABC):
1212
def __init__(self, endpoint: HttpUrl):
@@ -31,18 +31,18 @@ def fetch_all(self, doc_fields: List[str]) -> Iterator[Document]:
3131
while start < total_hits:
3232
batch = self.fetch_for_query_generation(
3333
documents_filter=None,
34-
doc_number=DOC_NUMBER_EACH_FETCH,
34+
number_of_docs=NUMBER_OF_DOCS_EACH_FETCH,
3535
doc_fields=doc_fields,
3636
start=start
3737
)
3838
if not batch:
3939
break
4040
for doc in batch:
4141
yield doc
42-
# if we didn't reach the end of the docs, then len(batch) == DOC_NUMBER_EACH_FETCH
43-
# if we reached the end of the docs. then len(batch) <= DOC_NUMBER_EACH_FETCH -> next iteration we exit the
44-
# loop since we are adding DOC_NUMBER_EACH_FETCH (not len(batch)) and start becomes greater than total_hits
45-
start += DOC_NUMBER_EACH_FETCH
42+
# if we didn't reach the end of the docs, then len(batch) == NUMBER_OF_DOCS_EACH_FETCH if we reached the
43+
# end of the docs. then len(batch) <= NUMBER_OF_DOCS_EACH_FETCH -> next iteration we exit the loop since
44+
# we are adding NUMBER_OF_DOCS_EACH_FETCH (not len(batch)) and start becomes greater than total_hits
45+
start += NUMBER_OF_DOCS_EACH_FETCH
4646

4747

4848
def _parse_query_template(self, path: Path | str) -> Dict[str, Any]:
@@ -72,7 +72,7 @@ def _replace_placeholder(self, obj: Any, placeholder: str, keyword: str | None)
7272
@abstractmethod
7373
def fetch_for_query_generation(self,
7474
documents_filter: Union[None, List[Dict[str, List[str]]]],
75-
doc_number: int,
75+
number_of_docs: int,
7676
doc_fields: List[str],
7777
start: int = 0) \
7878
-> List[Document]:

rre-tools/src/rre_tools/shared/search_engines/solr_search_engine.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,22 @@ def _get_total_hits(self, payload: Dict[str, Any]) -> int:
5757

5858
def fetch_for_query_generation(self,
5959
documents_filter: Union[None, List[Dict[str, List[str]]]],
60-
doc_number: int, doc_fields: List[str], start: int = 0) \
60+
number_of_docs: int, doc_fields: List[str], start: int = 0) \
6161
-> List[Document]:
6262
"""
6363
Fetches a set of documents from Solr for the purpose of query generation.
6464
6565
Args:
6666
documents_filter (Union[None, List[Dict[str, List[str]]]]): Optional filter constraints for fields and their allowed values.
67-
doc_number (int): Number of documents to retrieve.
67+
number_of_docs (int): Number of documents to retrieve.
6868
doc_fields (List[str]): List of field names to include in the output.
6969
start (int, optional): Starting index of the query. Defaults to 0.
7070
7171
Returns:
7272
List[Document]: A list of retrieved documents as `Document` objects.
7373
"""
7474
payload: Dict[str, Any] = self._fetch_all_payload
75-
payload['rows'] = doc_number
75+
payload['rows'] = number_of_docs
7676
payload['start'] = start
7777
payload['fl'] = self._unify_fields(doc_fields)
7878

rre-tools/src/rre_tools/shared/search_engines/vespa_search_engine.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def _normalize_field_value(v: Any) -> List[str]:
131131
def fetch_for_query_generation(
132132
self,
133133
documents_filter: Union[None, List[Dict[str, List[str]]]],
134-
doc_number: int,
134+
number_of_docs: int,
135135
doc_fields: Optional[List[str]],
136136
start: int = 0,
137137
) -> List[Document]:
@@ -140,7 +140,7 @@ def fetch_for_query_generation(
140140
141141
Args:
142142
documents_filter: Optional list of filter dictionaries for query restriction.
143-
doc_number: Number of documents to retrieve.
143+
number_of_docs: Number of documents to retrieve.
144144
doc_fields: Optional list of fields to include in the response.
145145
start: Optional start index to retrieve documents from.
146146
@@ -155,7 +155,7 @@ def fetch_for_query_generation(
155155
yql = self._build_yql(doc_fields or [], where)
156156

157157
payload["yql"] = yql
158-
payload["hits"] = int(doc_number)
158+
payload["hits"] = int(number_of_docs)
159159
payload["presentation.format"] = "json"
160160
payload['offset'] = start
161161

0 commit comments

Comments
 (0)