From 2c2185107347ba870dc45151104a979b70f22c20 Mon Sep 17 00:00:00 2001 From: Bernhard Merkle Date: Sat, 1 Aug 2026 17:56:24 +0200 Subject: [PATCH] Use module-qualified imports for storage.memory.propindex propindex (memory variant) exports a mix of an enum, several functions, and a class. Per AGENTS.md's import style guidelines, low-frequency symbols default to module-qualified: - query.py: lookup_property_in_property_index - secindex.py: build_property_index - storage/memory/provider.py: PropertyIndex - storage/sqlite/propindex.py: make_property_term_text, split_property_term_text (cross-imported from the memory variant) PropertyNames is left as a direct-symbol import everywhere (query.py, searchlang.py, searchlib.py): it's used 20+ times across those files, squarely matching the "avoiding severe repetitive visual clutter" exception in AGENTS.md. The sqlite variant's own class (SqlitePropertyIndex) exports a single class and is left as direct-symbol import, already compliant. Scope: src/typeagent only, per #298. Phase 2 (2/3) of the import-consistency cleanup tracked in #298. --- src/typeagent/knowpro/query.py | 5 +++-- src/typeagent/knowpro/secindex.py | 4 ++-- src/typeagent/storage/memory/provider.py | 6 +++--- src/typeagent/storage/sqlite/propindex.py | 17 +++++++---------- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/typeagent/knowpro/query.py b/src/typeagent/knowpro/query.py index 71dbf7ea..a237fd2c 100644 --- a/src/typeagent/knowpro/query.py +++ b/src/typeagent/knowpro/query.py @@ -7,8 +7,9 @@ from typing import cast, Literal, Protocol from ..aitools.embeddings import NormalizedEmbedding +from ..storage.memory import propindex from ..storage.memory.messageindex import IMessageTextEmbeddingIndex -from ..storage.memory.propindex import lookup_property_in_property_index, PropertyNames +from ..storage.memory.propindex import PropertyNames from .collections import ( Match, MatchAccumulator, @@ -600,7 +601,7 @@ async def lookup_property( property_value: str, ) -> list[ScoredSemanticRefOrdinal] | None: if context.property_index is not None: - return await lookup_property_in_property_index( + return await propindex.lookup_property_in_property_index( context.property_index, property_name, property_value, diff --git a/src/typeagent/knowpro/secindex.py b/src/typeagent/knowpro/secindex.py index f101f9cb..3593929b 100644 --- a/src/typeagent/knowpro/secindex.py +++ b/src/typeagent/knowpro/secindex.py @@ -1,8 +1,8 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. +from ..storage.memory import propindex from ..storage.memory.messageindex import build_message_index -from ..storage.memory.propindex import build_property_index from ..storage.memory.reltermsindex import build_related_terms_index from ..storage.memory.timestampindex import build_timestamp_index from .convsettings import ConversationSettings, RelatedTermIndexSettings @@ -66,5 +66,5 @@ async def build_transient_secondary_indexes[ await settings.get_storage_provider(), settings.related_term_index_settings, ) - await build_property_index(conversation) + await propindex.build_property_index(conversation) await build_timestamp_index(conversation) diff --git a/src/typeagent/storage/memory/provider.py b/src/typeagent/storage/memory/provider.py index 230b5b0a..96c189e0 100644 --- a/src/typeagent/storage/memory/provider.py +++ b/src/typeagent/storage/memory/provider.py @@ -5,6 +5,7 @@ from datetime import datetime, timezone +from . import propindex from ...knowpro.convsettings import MessageTextIndexSettings, RelatedTermIndexSettings from ...knowpro.interfaces import ( ChunkFailure, @@ -22,7 +23,6 @@ from .collections import MemoryMessageCollection, MemorySemanticRefCollection from .convthreads import ConversationThreads from .messageindex import MessageTextIndex -from .propindex import PropertyIndex from .reltermsindex import RelatedTermsIndex from .semrefindex import TermToSemanticRefIndex from .timestampindex import TimestampToTextRangeIndex @@ -35,7 +35,7 @@ class MemoryStorageProvider[TMessage: IMessage](IStorageProvider[TMessage]): _semantic_ref_collection: MemorySemanticRefCollection _conversation_index: TermToSemanticRefIndex - _property_index: PropertyIndex + _property_index: propindex.PropertyIndex _timestamp_index: TimestampToTextRangeIndex _message_text_index: MessageTextIndex _related_terms_index: RelatedTermsIndex @@ -58,7 +58,7 @@ def __init__( self._semantic_ref_collection = MemorySemanticRefCollection() self._conversation_index = TermToSemanticRefIndex() - self._property_index = PropertyIndex() + self._property_index = propindex.PropertyIndex() self._timestamp_index = TimestampToTextRangeIndex() self._related_terms_index = RelatedTermsIndex(related_terms_settings) thread_settings = message_text_settings.embedding_index_settings diff --git a/src/typeagent/storage/sqlite/propindex.py b/src/typeagent/storage/sqlite/propindex.py index 59a5a111..9bf8b190 100644 --- a/src/typeagent/storage/sqlite/propindex.py +++ b/src/typeagent/storage/sqlite/propindex.py @@ -8,10 +8,7 @@ from ...knowpro import interfaces from ...knowpro.interfaces import ScoredSemanticRefOrdinal -from ...storage.memory.propindex import ( - make_property_term_text, - split_property_term_text, -) +from ...storage.memory import propindex class SqlitePropertyIndex(interfaces.IPropertyToSemanticRefIndex): @@ -51,9 +48,9 @@ async def add_property( score = 1.0 # Normalize property name and value (to match in-memory implementation) - term_text = make_property_term_text(property_name, value) + term_text = propindex.make_property_term_text(property_name, value) term_text = term_text.lower() # Matches PropertyIndex._prepare_term_text - property_name, value = split_property_term_text(term_text) + property_name, value = propindex.split_property_term_text(term_text) # Remove "prop." prefix that was added by make_property_term_text if property_name.startswith("prop."): property_name = property_name[5:] @@ -87,9 +84,9 @@ async def add_properties_batch( else: semref_id = ordinal score = 1.0 - term_text = make_property_term_text(property_name, value) + term_text = propindex.make_property_term_text(property_name, value) term_text = term_text.lower() - property_name, value = split_property_term_text(term_text) + property_name, value = propindex.split_property_term_text(term_text) if property_name.startswith("prop."): property_name = property_name[5:] rows.append((property_name, value, score, semref_id)) @@ -109,9 +106,9 @@ async def lookup_property( value: str, ) -> list[interfaces.ScoredSemanticRefOrdinal] | None: # Normalize property name and value (to match in-memory implementation) - term_text = make_property_term_text(property_name, value) + term_text = propindex.make_property_term_text(property_name, value) term_text = term_text.lower() # Matches PropertyIndex._prepare_term_text - property_name, value = split_property_term_text(term_text) + property_name, value = propindex.split_property_term_text(term_text) # Remove "prop." prefix that was added by make_property_term_text if property_name.startswith("prop."): property_name = property_name[5:]