File size: 1,503 Bytes
98c76e4 893f9d6 98c76e4 c8b54b3 98c76e4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
from typing import List
from langchain_core.documents import Document
from functions.utils import find_required_parent_geographies
from functions.vector_databases.census_dhc_dp_techdoc import census_dhc_dp_techdoc
def required_geograpy_hierarchy_parents(geography_hierarchy: str) -> List[str | None]:
"""
Given the intent to look up a geography hierarchy within from U.S. Census Bureau 2020 decennial census demographic profile API,
return the parent geographies that must be included
Args:
geography_hierarchy (str): The geographic level to query (e.g. 'region', 'state', 'county', 'principal city (or part)', etc.).
Returns:
List[str]: List of strings representing the required parent geographies.
"""
return find_required_parent_geographies(geography_hierarchy)
def dec2020_dhc_semantic_search(
query: str,
) -> List[Document]:
"""
Perform a semantic search on the 2020 Census Demographic and Housing Characteristics File (DHC) housed at https://www2.census.gov/programs-surveys/decennial/2020/technical-documentation/complete-tech-docs/demographic-and-housing-characteristics-file-and-demographic-profile/2020census-demographic-and-housing-characteristics-file-and-demographic-profile-techdoc.pdf
Args:
query (str): The semantic query to perform.
Returns:
(List[Document]): The semantically related documents
"""
docs = census_dhc_dp_techdoc.vector_store.similarity_search(query, k=4)
return docs
|