跳到正文
DEV Community· Hornet-Wing·· 5 小時前AI 評分44

Memory Lantern:忘記字句時找回舊故事

Memory Lantern: finding old stories when you’ve forgotten the words

AI 導讀

Memory Lantern 是一款以 AI 搜尋已儲存回憶的應用程式,讓用戶記不起原文用詞時,仍可按記憶內容找出相關段落。語意搜尋使用 all-MiniLM-L6-v2,透過 Transformers.js 3.8.1 在用戶裝置上運行。無需帳戶或 API key,筆記和搜尋內容不會上傳至推理伺服器。

正文

This is a submission for the Hacktoberfest Open-Source AI Challenge Week 4: Ghost in the Machine.

What I Built

Sometimes you remember what a story was about, but not the words someone used to tell it. A dented cake tin. A train ticket. The way somebody fixed a broken radio rather than throwing it away.

Memory Lantern is a small collection for those memories. Add notes about people, places, and ordinary moments, then search for what you remember. The AI’s job is to find related passages in the notes you actually saved. Every result opens the original text.

For “Ghost in the Machine,” I wanted to help the past remain accessible. The app holds onto people’s words and makes them easier to find. An example collection contains eight clearly labeled fictional memories so visitors can try the idea before adding their own.

Demo

Try Memory Lantern

To try the difference between the two search modes:

  1. Search food she made for celebrations with Match words selected.
  2. Enable meaning search and compare the results for the same query.
  3. Open a result to read the complete source note.

The example collection includes a birthday baking memory called “The lemon cake tin.” Its vocabulary differs from the query, which makes it a useful case for checking semantic retrieval. The model ranks the results; the app has no hardcoded answer for this query.

No account or API key is needed. Initial model loading requires internet, and the interface shows download progress. Visitors can also add a memory, reload to check that it was saved, and export the collection.

Code

Source code and setup instructions

The app and original fictional example collection are MIT licensed. Runtime code and model weights are downloaded separately under their respective licenses.

How I Built It

The app is plain HTML, CSS, and JavaScript, served as static files. Memories are stored in the browser and can be exported as a restorable JSON backup or a self-contained HTML reading copy. The reading copy contains no scripts or external assets.

Meaning search runs all-MiniLM-L6-v2, using Xenova’s ONNX port, in a module Web Worker. Transformers.js 3.8.1 runs q8 weights with ONNX Runtime’s WASM CPU backend. Both queries and notes use mean pooling and L2 normalization.

Long notes are split into overlapping source passages to reduce truncation. The worker caches their embeddings in memory and re-encodes changed notes on the next search. Cosine similarity selects the best passage for each memory, then ranks the memories. The model encodes and compares text; it does not write any memories or answers.

flowchart LR
    Notes[Original memories] --> Passages[Source passages]
    Passages --> Model[Local MiniLM worker]
    Query[Search thought] --> Model
    Model --> Similarity[Cosine ranking]
    Similarity --> Original[Passage and complete original note]
    Notes --> Backup[JSON backup and HTML reading copy]

Two details matter for trust. A nearest neighbor can still be irrelevant, so results show similarity scores and original passages. Word matching stays available for exact details. Download or inference failures produce an error, with no silent change of search method.

Ten logic tests cover backup round trips, malformed imports, merge behavior, long-note passage coverage, retrieval ranking, safe exports, and worker cancellation/recovery. The repository also includes an optional browser check that downloads the real model and exercises the example query.

Why Does Open Innovation Matter?

The search model is downloadable and can run on the reader’s device. There is no inference account or API key to obtain, and no per-query inference service to pay for. The app can be hosted as static files, and its search code and weights can be inspected or replaced.

That is especially useful for personal memories. The app does not upload notes or search queries to an inference server. Loading meaning search still fetches code from jsDelivr and files from Hugging Face, which receive normal download metadata. Browser storage is not encrypted, synced, or backed up automatically, so the export feature is part of the core experience.

There are tradeoffs: the model weights take about 23 MB plus runtime files, the model works best with English, and semantic similarity can miss a useful memory. Code/runtime loading can still need internet after a reload. The standalone reading copy provides a simple way to preserve the collection independently of the application.

What Informed the Build

Gabriel Anhaia’s explanation of pooling and normalization reinforced the need to encode notes and queries consistently. Divyakush Punjabi’s “Similarity isn't relevance” informed the way results are presented: source passages and a similarity ranking rather than an assertion that the app knows the answer. No article code was copied.

This app and post were created with AI coding and writing assistance. The model and Transformers.js are Apache-2.0 licensed; ONNX Runtime is MIT licensed. I’m entering the overall category.

來源:DEV Community · dev.to