Skip to content

Commit abcd2e5

Browse files
committed
Fixed SearchIndex default index_directory being a default_factory (#1070)
1 parent a19932d commit abcd2e5

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/paperqa/agents/search.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from collections import Counter
1515
from collections.abc import AsyncIterator, Callable, Sequence
1616
from enum import StrEnum, auto
17-
from typing import TYPE_CHECKING, Any, ClassVar
17+
from typing import TYPE_CHECKING, Any, ClassVar, cast
1818

1919
import anyio
2020
from pydantic import BaseModel, JsonValue
@@ -120,9 +120,7 @@ def __init__(
120120
self,
121121
fields: Sequence[str] | None = None,
122122
index_name: str = "pqa_index",
123-
index_directory: str | os.PathLike = IndexSettings.model_fields[
124-
"index_directory"
125-
].default,
123+
index_directory: str | os.PathLike | None = None,
126124
storage: SearchDocumentStorage = SearchDocumentStorage.PICKLE_COMPRESSED,
127125
):
128126
if fields is None:
@@ -133,6 +131,11 @@ def __init__(
133131
f"{self.REQUIRED_FIELDS} must be included in search index fields."
134132
)
135133
self.index_name = index_name
134+
if index_directory is None: # Pull from settings
135+
index_directory = cast(
136+
Callable[[], str | os.PathLike],
137+
IndexSettings.model_fields["index_directory"].default_factory,
138+
)()
136139
self._index_directory = index_directory
137140
self._schema: Schema | None = None
138141
self._index: Index | None = None

0 commit comments

Comments
 (0)