Ilm (イルム) is Arabic for "knowledge," but in this project, it symbolizes an AI that pursues "ephemeral inspiration."
Many modern AIs maintain conversational continuity by retaining context. The trade-off is that their thinking can become "trapped" by past dialogue, hindering free and creative ideation. When asked for new ideas, an AI often returns similar responses influenced by the preceding conversation.
Ilm is designed to solve this challenge. Its memory structure is based on an analogy of human memory.
L0: Working Memory (Consciousness): The cognitive space for generating responses is completely refreshed with every turn. No specific conversational text is carried over, allowing the AI to focus solely on the input of the "here and now." This enables fresh responses, untethered by past thoughts.
L1: Episodic Memory (Echo): It retains only the keywords from the last few conversational turns. When the user mentions one of these keywords again, the AI shows a semblance of recalling a fragment of memory, like déjà vu, adding a human-like depth to the conversation.
L2: Semantic Memory (Deep Experience): It does not store specific conversation content. Instead, it perpetually learns abstract patterns, suchs as "from which topic to which topic do transitions occur?" Based on this experience, the AI judges whether a topic shift is a "natural flow" or a "novel leap" and adjusts its response nuance accordingly.
Through this hierarchical memory system, Ilm aims for a human-like intelligence that combines ephemeral, refreshed thinking with accurate judgments based on long-term, abstracted experience.
Implemented Features
Dynamic Prompt Generation: Constructs instructions (prompts) for the AI in real-time based on user input and the conversational context.
Intent & Style Detection: Analyzes whether user input is a "Question" or a "Request for Ideas," and whether the writing style is "Polite" or "Concise," to optimize the AI's response tone.
Topic Transition Detection & Judgment: Detects shifts in conversational topics and, based on L2 long-term memory, judges whether the transition is "natural" or "novel."
Flashback (Echoing Memory): If the user reuses a keyword the AI recently mentioned, it generates a response that seems to recall the previous context.
Long-Term Experience Accumulation: Persistently records topic transition patterns in a SQLite database (experience.db), accumulating them as the AI's "experience."
Architecture
This application implements a "Hierarchical Memory System" composed of the following components:
Conductor: The main logic within app_structured.py. It acts as the central module that receives user input, queries the memory layers, and constructs the final prompt for the LLM.
L0 (Working Memory): The ephemeral, single-use prompt passed to the LLM.
L1 (Episodic Memory): A short-term keyword buffer implemented with deque.
L2 (Semantic Memory): A persistent database implemented with SQLite that records topic transition patterns.
Setup and Usage
Clone the Repository:
bash
1git clone <your-repo-url>2cd ilm-finetune
Create a Virtual Environment:
bash
1python3 -m venv venv
2source venv/bin/activate
Install Dependencies:
pip install -r requirements.txt
Prepare the Fine-Tuned Model:
This project assumes that a fine-tuned model exists in the ./merged_model directory. The fine-tuning was performed using mlx_lm.
(Note: The specific steps for fine-tuning are outside the scope of this project, but the commands used during development are shown below for reference.)