Code Reference, Core & Search¶
Auto-generated from source for the shared core models and the legacy search stack.
Core¶
common¶
common
¶
Item
dataclass
¶
clean_payload_field
¶
hit_to_item
¶
Convert a Qdrant point to a small, standardized dict without assuming anything about the payload structure.
Source code in ai-engine\src\ai_engine\common.py
limit_text
¶
limit_text("hello world", 5) 'hello...'
limit_text("hello world", 100) 'hello world'
:param text: Text to limit :param lim: Max length :return: Limited text
Source code in ai-engine\src\ai_engine\common.py
highlight_search_match
¶
highlight_search_match("hello world", "world") 'hello world'
highlight_search_match("hello world", "hello") 'hello world'
highlight_search_match("hello world", "hell") 'hello world'
highlight_search_match("Hello world", "hell") 'Hello world'
highlight_search_match("hello world", "foo") 'hello world'
highlight_search_match("hello world", "ello") 'hello world'
:param text: Found string :param query: Search query :param before: Tag before match :param after: Tag after match :return: Highlighted string
Source code in ai-engine\src\ai_engine\common.py
config¶
config
¶
user_state¶
user_state
¶
UserState
¶
Source code in ai-engine\src\ai_engine\user_state.py
is_interaction_successful
¶
Determine if user interaction is successful based on dwell time compared to estimated reading time.
Source code in ai-engine\src\ai_engine\user_state.py
compute_reading_time
¶
Estimate reading time for given content length in words. If content has an image, add extra fixed time.
Source code in ai-engine\src\ai_engine\user_state.py
projection_builder¶
projection_builder
¶
ProjectionBuilder
¶
Source code in ai-engine\src\ai_engine\projection_builder.py
get_user_projection
¶
Compute user projection embedding based on recent events.
Source code in ai-engine\src\ai_engine\projection_builder.py
get_user_profile_as_text
¶
Retrieve the user profile as a string
Source code in ai-engine\src\ai_engine\projection_builder.py
db_interface¶
db_interface
¶
DB_Interface
¶
Source code in ai-engine\src\ai_engine\db_interface.py
register_session
¶
Creates a new device row (if needed) and a new session row using the input schema.
Source code in ai-engine\src\ai_engine\db_interface.py
narrative¶
narrative
¶
OpenRouterAdapter
¶
Acts as a drop-in replacement for ollama.Client() for testing. Uses the OpenAI SDK pointed at the OpenRouter API.
Source code in ai-engine\src\ai_engine\narrative.py
chat
¶
Simulates the ollama.Client().chat() method structure.
Source code in ai-engine\src\ai_engine\narrative.py
KeycloakTokenClient
¶
KeycloakTokenClient(
base_url: str = KEYCLOAK_BASE_URL,
realm: str = KEYCLOAK_REALM,
client_id: str = KEYCLOAK_CLIENT_ID,
client_secret: str = KEYCLOAK_CLIENT_SECRET,
username: str = KEYCLOAK_USERNAME,
password: str = KEYCLOAK_PASSWORD,
safety_margin_seconds: int = 30,
)
Fetches and refreshes Keycloak tokens as needed.
base_url: e.g. "https://keycloak.dev.memorise.sdu.dk" realm: e.g. "oauth2-proxy"
Source code in ai-engine\src\ai_engine\narrative.py
get_access_token
¶
Public API: Always returns a valid (or freshly refreshed) access token.
Source code in ai-engine\src\ai_engine\narrative.py
OllamaClient
¶
OllamaClient(
base_url: str = OLLAMA_BASE_URL,
model: str = OLLAMA_MODEL,
*,
token_client: KeycloakTokenClient,
)
Simple Ollama client that uses KeycloakTokenClient for auth. Can be used as a backend where you'd otherwise use OpenRouterAdapter.
base_url: e.g. "https://ollama.dev.memorise.sdu.dk"
Source code in ai-engine\src\ai_engine\narrative.py
list_models
¶
show_model
¶
POST /api/show Get detailed info for a model.
chat
¶
Call POST /v1/chat/completions and normalize the result to:
{
"model": model,
"created_at": "...",
"message": {
"role": "assistant",
"content": "
Source code in ai-engine\src\ai_engine\narrative.py
embeddings
¶
embeddings(
model: str,
input_text: str,
extra_params: Optional[Dict[str, Any]] = None,
) -> Dict[str, Any]
Call the Ollama /api/embeddings endpoint.
Returns whatever Ollama returns, typically: { "embedding": [float, float, ...] }
Source code in ai-engine\src\ai_engine\narrative.py
Search¶
global_searcher¶
global_searcher
¶
GlobalSearch
¶
Source code in ai-engine\src\ai_engine\search\global_searcher.py
search
¶
search(
text: Optional[str] = None,
*,
lat: Optional[float] = None,
lon: Optional[float] = None,
radius_meters: Optional[float] = None,
) -> SearchResult
Unified search behavior: - q only -> vector search - geo only (lat/lon) -> geo search - q + geo -> hybrid search
Source code in ai-engine\src\ai_engine\search\global_searcher.py
similar
¶
similar(
item_id: int,
*,
exclude_self: bool = True,
vector_name: Optional[str] = None,
) -> SearchResult
Similar items for a given item_id: - fetch point vector by id - run vector similarity search
Source code in ai-engine\src\ai_engine\search\global_searcher.py
vector_searcher¶
vector_searcher
¶
user_to_query_text
¶
Convert user profile into a short natural-language description that the embedding model can understand.
Source code in ai-engine\src\ai_engine\search\vector_searcher.py
geo_searcher¶
geo_searcher
¶
GeoSearch
¶
Simple helper class for doing geo-based searches in Qdrant.
:param api_url: Qdrant API URL :param api_key: Qdrant API key :param collection_name: Name of the collection to search
Source code in ai-engine\src\ai_engine\search\geo_searcher.py
geo_filter
¶
Build a geo-radius filter.
Source code in ai-engine\src\ai_engine\search\geo_searcher.py
search
¶
Pure geo search using scroll (no vector similarity).
:returns: (points, next_offset)
Source code in ai-engine\src\ai_engine\search\geo_searcher.py
hybrid_search
¶
hybrid_search(
query_vector,
lat: float,
lon: float,
radius_meters: float = 5000,
limit: int = 10,
search_params: SearchParams | None = None,
query_text: str | None = None,
)
Example hybrid search: vector similarity + geo constraint.
Source code in ai-engine\src\ai_engine\search\geo_searcher.py
user_searcher¶
user_searcher
¶
help_searcher¶
help_searcher
¶
CommonSearch
¶
Source code in ai-engine\src\ai_engine\search\help_searcher.py
get_item
¶
Fetch item by Point ID.
Source code in ai-engine\src\ai_engine\search\help_searcher.py
get_vector
¶
Fetch item by Point ID.
Source code in ai-engine\src\ai_engine\search\help_searcher.py
get_random_item
¶
Fetch random items
Source code in ai-engine\src\ai_engine\search\help_searcher.py
get_item_by_item_id
¶
Fetch item by ID.