Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
from e84_geoai_common.util import timed_function

from natural_language_geocoding.geocode_index.geoplace import GeoPlaceType, Hierarchy
from natural_language_geocoding.geocode_index.index import GEOPLACE_INDEX_NAME, GeoPlaceIndexField
from natural_language_geocoding.geocode_index.index import (
GEOCODE_INDEX_CACHE_DIR,
GEOPLACE_INDEX_NAME,
GeoPlaceIndexField,
)
from natural_language_geocoding.geocode_index.opensearch_utils import (
QueryDSL,
create_opensearch_client,
Expand Down Expand Up @@ -236,9 +240,12 @@ class PlaceCache:

_cache_file: Path

def __init__(self, *, cache_dir: str | Path = "./temp", force_reload: bool = False) -> None:
def __init__(
self, *, cache_dir: str | Path | None = None, force_reload: bool = False
) -> None:
# Increment the name of the file when something changes about the format of the storage
self._cache_file = Path(cache_dir) / "hierarchical_place_cache_v2.json"
resolved_cache_dir = cache_dir or GEOCODE_INDEX_CACHE_DIR
self._cache_file = Path(resolved_cache_dir) / "hierarchical_place_cache_v2.json"
if force_reload or not self._cache_file.exists():
self._dicts = _populate()
self._cache_file.parent.mkdir(exist_ok=True)
Expand Down
2 changes: 2 additions & 0 deletions src/natural_language_geocoding/geocode_index/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import json
import logging
import os
import subprocess
from abc import ABC, abstractmethod
from collections.abc import Iterable
Expand Down Expand Up @@ -187,6 +188,7 @@ class GeoPlaceDoc(TypedDict):


GEOPLACE_INDEX_NAME = "geoplaces"
GEOCODE_INDEX_CACHE_DIR = os.getenv("GEOCODE_INDEX_CACHE_DIR", "./temp")

# The set of geo place types for which we'll index geometry spatially.
# We don't do this for all types due to some issues getting everything to index. In the future, we
Expand Down
Loading