DEV Community· Samad khalid·· 6 天前AI 評分45
react-native-ultrastore v3.1.0:零依賴 MMKV v4 狀態管理,支援裝置端向量搜尋與串流快取
react-native-ultrastore v3.1.0: Zero-Dependency MMKV v4 State with On-Device Vector & Stream Cache
AI 導讀
react-native-ultrastore 推出 v3.1.0,以 MMKV v4 和 Nitro Modules 建構零依賴、同步的 JSI runtime,整合儲存、響應式狀態、裝置端向量搜尋及 LLM 串流快取。套件大小為 36.1 kB,支援約 50k 個向量的本機搜尋,並包括 42 項生命週期測試。
正文
Building offline-first AI features in React Native (New Architecture) usually means stitching together MMKV for persistence, Zustand for reactive state, and custom native bridges for vector search or token streaming.
I just shipped v3.1.0 of react-native-ultrastore to unify all three into a single, zero-dependency, synchronous JSI runtime built on MMKV v4 + Nitro Modules.
What’s Inside (36.1 kB, 0 Dependencies)
-
Synchronous JSI Storage & State: Reactive hooks (
useUltraStore), atomicsetManybatching, encrypted namespaces, and strict schema migrations with zero async bridge overhead. -
On-Device Vector Search (
react-native-ultrastore/ai): Cosine similarity search operating directly on cachedFloat32Arraybuffers without re-validation overhead—ideal for local RAG/embeddings under ~50k vectors. -
Bounded LLM Stream Cache (
UltraStreamCache): High-frequency token buffering with automatic memory cleanup and snapshot caching so streaming AI responses don't choke React renders. -
Production Hardening: Automatic recovery for corrupted disk payloads, stale query cancellation in
useUltraQuery, and 42 lifecycle tests. -
AI-Agent Ready: Ships with root
llms.txt,llms-full.txt, and.cursorrulesso Cursor and Claude generate accurate, idiomatic code out of the box.
Quick Example
tsx
import { createUltraStore, useUltraStore } from 'react-native-ultrastore';
import { VectorStore, UltraStreamCache } from 'react-native-ultrastore/ai';
// 1. Synchronous MMKV v4 store
const store = createUltraStore({ id: 'app-store' });
// 2. On-device vector similarity search
const vectors = new VectorStore({ dimensions: 384 });
await vectors.add('doc-1', new Float32Array(384), { title: 'Offline RAG' });
const matches = await vectors.search(queryEmbedding, { topK: 5 });
// 3. Bounded LLM token stream cache
const streamCache = new UltraStreamCache({ maxTokens: 4096 });
streamCache.append('msg-1', 'Hello ');
來源:DEV Community · dev.to