rag_system.auto_search module
RAG Auto-Search Manager.
Manages per-channel auto-search configuration and provides context injection for automatic RAG searches on user messages.
Adapted for the v3 multi-platform architecture: channel keys use
platform:channel_id composite format.
- class rag_system.auto_search.RAGAutoSearchManager(redis_client)[source]
Bases:
objectPer-channel RAG auto-search configuration and query fan-out, backed by Redis.
Stores one config record per channel under the
stargazer:v3:rag:auto_search:Redis key prefix and, when a channel is enabled, automatically runs a semantic search across its configured stores for every inbound user message so the result can be injected into the LLM context. This is what makes a channel “RAG-aware” without the user having to invoke a tool. It owns no other state: all persistence is plain RedisGET/SET/SCAN/DELETEon string keys (config) andSISMEMBERonstargazer:v3:cloud_rag:shared:sets (cloud-store access control), while the actual vector search is delegated torag_system.file_rag_manager.FileRAGManagerinstances resolved viarag_system.file_rag_manager.get_rag_store().Constructed with a live
redis.asyncioclient by the RAG tool layer (tools/rag.py,tools/cloud_rag.py), the web config API (web/rag_config_api.py), and the inference message pipeline, whosesearch_for_message()is called per message frommessage_processor.generate_and_send.- Parameters:
redis_client (aioredis.Redis)
- __init__(redis_client)[source]
Initialize the instance.
- Parameters:
redis_client (
Redis) – Redis connection client.- Return type:
None
- async set_channel_config(channel_key, store_names, enabled=True, n_results=3, min_score=0.5)[source]
Write (create or overwrite) the auto-search config for one channel.
Builds the canonical config dict, clamps
n_resultsto the 1-10 range andmin_scoreto 0.0-1.0 so callers cannot persist out-of-band values, stamps a freshupdated_attimestamp, and JSON-serializes it into the single Redis keystargazer:v3:rag:auto_search:<channel_key>viaSET. Once written,search_for_message()will start auto-searching that channel on the next message. Aninfolog line records the change.Called by the RAG admin tools in
tools/rag.pyandtools/cloud_rag.py(enable/share handlers) and by the web config API inweb/rag_config_api.pyto persist user edits.- Parameters:
channel_key (
str) – Composite"platform:channel_id"identifier.store_names (
List[str]) – RAG store names to search for this channel.enabled (
bool) – Whether auto-search is active for the channel.n_results (
int) – Number of chunks to inject; clamped to 1-10.min_score (
float) – Minimum similarity to keep a chunk; clamped to 0.0-1.0.
- Returns:
The persisted config dict (post-clamping, with the new
updated_atvalue).- Return type:
- async get_channel_config(channel_key)[source]
Load and decode the persisted auto-search config for a channel.
Reads the
stargazer:v3:rag:auto_search:<channel_key>Redis key with a singleGETand JSON-decodes it, returningNonewhen the channel was never configured. This is the canonical read used both to render current settings and to gate whether a message should be auto-searched at all.Called internally by
search_for_message()(the enablement check) anddisable_channel(), by the web config API inweb/rag_config_api.py, by the cloud-RAG share/unshare tools intools/cloud_rag.py, and by the RAG status tool intools/rag.py.
- async disable_channel(channel_key)[source]
Turn off auto-search for a channel without discarding its store list.
Loads the existing config via
get_channel_config(), flipsenabledtoFalse, refreshesupdated_at, and writes the record back with a RedisSET. This is a soft toggle: the configuredstore_namesare preserved so the channel can be re-enabled later without re-selecting stores. ReturnsFalse(a no-op) when the channel was never configured.Called by the RAG admin tool in
tools/rag.py(the disable action).
- async remove_channel_config(channel_key)[source]
Permanently delete a channel’s auto-search config from Redis.
Issues a single
DELon thestargazer:v3:rag:auto_search:<channel_key>key. Unlikedisable_channel(), this discards the storedstore_namesentirely, so the channel reverts to having no RAG configuration at all.Called by the web config API in
web/rag_config_api.py, by the RAG admin tool intools/rag.py, and by the cloud-RAG unshare flow intools/cloud_rag.pywhen the last shared store is removed.
- async list_configured_channels()[source]
Enumerate every channel that currently has an auto-search config.
Walks all
stargazer:v3:rag:auto_search:*keys with a non-blockingSCANiterator andGET-decodes each into its config dict. Used to render an admin overview of which channels have RAG enabled and against which stores; the scan plus per-key fetch makes this O(number of configured channels) rather than a single bulk read.Called by the web config API in
web/rag_config_api.pyand by the RAG status/listing tool intools/rag.py.
- async search_for_message(channel_key, message_content, chunk_size=10000, query_embedding=None, user_id='')[source]
Perform auto-search if the channel is configured.
- Parameters:
query_embedding (
list[float] |None) – Pre-computed 3072-d embedding for message_content. When provided it is forwarded to the pgvector store as the KNN query vector, skipping a redundant embedding call.user_id (
str) – The message author. Used to enforce access control oncloud_usr_stores.string (Returns XML-formatted RAG context)
None. (or)
channel_key (str)
message_content (str)
chunk_size (int)
- Return type: