How I made a system that doesn't let content vanish
One of the main tasks of this project isn’t only answering people but also bringing material back to life.
For this the bot has a separate content base. It stores not only the materials themselves but also their descriptions. It’s by these descriptions that the system understands what can appear in a conversation again and when.
One of the key fragments looks like this:
def load_content_index(path: str = CONTENT_JSON_PATH):
global _content_loaded, content_index, content_embeddings
if _content_loaded:
return
with open(path, "r", encoding="utf-8") as f:
raw = json.load(f)
content_index = raw.get("items", []) or []
content_embeddings = [_extract_embedding(item) for item in content_index]
_content_loaded = True
What matters here:
• load_content_index(…) The function loads the content base from content.json.
• global _content_loaded, content_index, content_embeddings Shared variables are declared here, in which the loaded content then lives.
• if _content_loaded: return If the base is already loaded, there’s no need to read the file again. This saves time and avoids extra work.
• json.load(f) Reads the whole JSON file.
• content_index = raw.get(“items”, []) or [] Gets the list of materials. So the bot works with a separate content index. If there’s no items key, an empty list is used.
• content_embeddings = [_extract_embedding(item) for item in content_index] An embedding is pulled out separately for each item. So content is stored not only as text or a link but also as a vector for semantic search.
• _content_loaded = True A mark that the base is already in memory.
From there the project can choose suitable material not at random but by semantic closeness to the current conversation.
Another important node:
picked = pick_relevant_content(query_text, top_k=CONTENT_TOP_K)
if picked:
send_content_to_chat(chat_id, picked)
What happens here:
• pick_relevant_content(query_text, top_k=CONTENT_TOP_K) The system takes the current text or topic of the conversation and looks for the most suitable items among the content.
• query_text This is what the search starts from: a message, a topic or an assembled context.
• top_k=CONTENT_TOP_K Limits the number of candidates. The bot doesn’t drag in everything, it picks only the top matches.
• if picked: If suitable material is found, the bot goes on.
• send_content_to_chat(chat_id, picked) Sends the found material back to the chat.
This is where recirculation begins. The material doesn’t lie in a dead archive. It can appear in a conversation again if the system understands there’s a place for it now.
So the logic here is:
- content is stored separately
- it has embeddings
- the bot can search by meaning
- the material found returns to the chat
- old things don’t vanish but get a new point of entry
So for me this project isn’t just a bot. It’s a system in which memory works not only for replies but also for bringing material back to life.



