Local Semantic Search: From Indexing to Video Timestamp Navigation
This guide explains how a local multimodal semantic search system works on a personal computer. It covers scanning and extracting text from documents, PDFs, images, audio, and video, encoding and storing vectors, returning results with timestamps for jumping to video positions, incremental indexing, hardware trade-offs, and safe handling of personal files. It includes a minimal Python example and a checklist for a small test run.
1. The Problem to Solve
Filename search only matches literal text. If you want to find “the document about cache invalidation strategies” or “the part of the video that mentions connection pools,” keywords often fall short. Semantic search converts file content into vectors and matches a question against content by similarity, so it can answer these fuzzy queries.
This article focuses on a class of local multimodal semantic search systems that run on a personal computer. They cover documents, images, PDFs, audio recordings, and video, and they support jumping to a point in time in a video. Rather than listing open-source projects one by one, this article explains how these systems work and how to put them into practice. When choosing a specific project, check three things: whether it has complete deployment documentation, whether its license fits your use case, and whether it still has recent commits.
2. Overall Pipeline
A complete system usually has four steps:
- Scan: Walk through the authorized directories and record each file’s path, type, size, modification time, and content hash.
- Extract: Convert files to text. Extract text directly from PDFs, and run OCR on scanned documents first. Use speech recognition to generate timestamped text from audio and video. For images, either generate descriptions with a multimodal model or encode image-text vectors directly.
- Encode and write: Use an embedding model to convert each text chunk into a vector, then write the vector to the local index along with its metadata.
- Query: Encode the user’s question as a vector, retrieve the most similar chunks, and return the file path, the original chunk text, and the timestamp.
Step 2 sets the upper limit on retrieval quality. If OCR contains many errors, or speech transcription misses key terms, even a strong embedding model cannot retrieve the right content. When debugging, check the extraction results first, then adjust the models.
3. A Minimal Working Example
The code below is a structural example. It uses the encoding interface of sentence-transformers and SQLite for storage. Before running it, install the dependencies and replace the model name with the multilingual embedding model you choose. Check that model’s model card for the correct name and parameters.
import hashlibimport sqlite3from pathlib import Pathimport numpy as npfrom sentence_transformers import SentenceTransformerMODEL = SentenceTransformer("your-chosen-multilingual-embedding-model") # Replace with the model name from its model cardDB = sqlite3.connect("index.db")DB.execute("""CREATE TABLE IF NOT EXISTS chunks (id INTEGER PRIMARY KEY,path TEXT,start REAL,end REAL,text TEXT,sha TEXT,vec BLOB)""")def file_sha(p: Path) -> str:h = hashlib.sha256()with p.open("rb") as f:for block in iter(lambda: f.read(1 << 20), b""):h.update(block)return h.hexdigest()def needs_update(path: Path, sha: str) -> bool:row = DB.execute("SELECT 1 FROM chunks WHERE path = ? AND sha = ? LIMIT 1",(str(path), sha),).fetchone()return row is Nonedef index_file(path: Path, chunks):"""chunks: [(start_sec, end_sec, text), ...]. If a document has no timestamps, set start and end to None."""sha = file_sha(path)if not needs_update(path, sha):returntexts = [c[2] for c in chunks]vecs = MODEL.encode(texts, normalize_embeddings=True) # If encoding fails, an exception is raised and the code below does not commitDB.execute("DELETE FROM chunks WHERE path = ?", (str(path),))for (s, e, t), v in zip(chunks, vecs):DB.execute("INSERT INTO chunks (path, start, end, text, sha, vec) VALUES (?, ?, ?, ?, ?, ?)",(str(path), s, e, t, sha, v.astype(np.float32).tobytes()),)DB.commit()def search(query: str, top_k: int = 5):q = MODEL.encode([query], normalize_embeddings=True)[0]rows = DB.execute("SELECT path, start, end, text, vec FROM chunks").fetchall()scored = []for path, s, e, t, blob in rows:v = np.frombuffer(blob, dtype=np.float32)scored.append((float(v @ q), path, s, e, t))scored.sort(reverse=True)return scored[:top_k]
This example compares the query against every stored vector on each search. That is fast enough for up to a few tens of thousands of chunks. For larger datasets, switch to FAISS or to an SQLite extension that supports vector search.
Each result includes a similarity score, the file path, the start and end times in seconds, and the original text chunk. When you show results to users, display all three of these fields so people can verify them manually.
4. How to Locate a Point in a Video
Each segment output by a speech recognition tool, such as the Whisper series, includes start and end fields in seconds. Treat each transcript segment as one chunk and keep both fields. When a query hits a chunk, pass its start value to the video player’s seek parameter.
Use the following chunking rules as a starting point, and adjust them to your content:
- Split on sentence boundaries or speech pauses, so that one sentence does not span two chunks.
- Merge chunks that are too short (for example, fewer than 20 characters) with an adjacent chunk to reduce noise.
- Split chunks that are too long (for example, more than 300 characters). Keep an overlap of one or two sentences between the new chunks, so key information does not get lost at a boundary.
The accuracy of timestamp jumps depends on the timestamp quality from speech recognition. Before launch, click through a sample of results to confirm that each jump lands at the right position, and record the hit rate. If the offset is a consistent few seconds, the transcription timestamps are usually shifted. Correct the offset uniformly during chunking.
5. Incremental Indexing and Resource Management
The basic approach to incremental updates is to compute a SHA-256 hash for each file and compare it with the hash recorded in the index. If the hash is unchanged, skip the file. If the hash has changed, delete that file’s old chunks and rebuild them.
Modification time (mtime) alone is not reliable. Backup or copy tools may change mtime even when the content stays the same. The content can also change while mtime is preserved. In practice, first compare the file size and mtime. If both are unchanged, skip the file. Compute the hash only when one of them has changed. This avoids most of the computation cost.
For resource management, load embedding and speech recognition models on demand, because they are large. When the retrieval service has been idle for a while, unload the models from GPU memory or RAM. When encoding in batches, limit the batch size to cap memory use per run. For speech recognition, start with a smaller model version, verify the results, and then decide whether to upgrade.
6. Hardware and VRAM Choices
Prices for storage and GPU memory hardware have fluctuated recently, so check current market prices for specifics. Heavy demand for high-bandwidth memory from AI data centers is considered one of the factors affecting the supply of consumer GPU memory.
For developers choosing hardware, there are two main paths:
- Developers with ample hardware: You can run larger multimodal models locally for stronger image understanding. Reserve VRAM for other applications, so the retrieval service does not compete with games or creative software for resources.
- Developers with limited hardware: Choose small embedding models and quantized speech recognition models. Even without a dedicated GPU, you can run indexing on a CPU, though it will be slower.
A tiered setup usually works best. Send frequent retrieval and classification tasks to a small local model, and send occasional complex reasoning to a larger local model or a cloud service. This controls costs and keeps private data on the device.
7. Risk Control for Local Scanning
These tools read large amounts of personal or enterprise files, so isolate them before deployment:
- Read-only scanning: The scan stage does not modify any source files. The index is written only to a separate directory.
- Limited scope: Authorize only specific directories. Do not point the tool at an entire user home directory or at system directories.
- Back up the index: If the index is corrupted, you can rebuild it from the source files. Regular backups save that rebuild time.
- Check for outbound connections: Confirm that the tool does not upload file contents to external services. If needed, restrict network access with a firewall or a container.
- Confirm compliance requirements: For files that contain personal information or are subject to compliance rules, confirm the permitted use and retention period first.
- Clean up deleted files: When a source file is deleted, remove its chunks from the index as well. Otherwise, queries will return paths that no longer exist.
8. Minimal Demo Checklist
- Install the dependencies, and confirm that both the embedding model and the speech recognition model load correctly.
- Prepare a test directory with about a dozen files, covering documents, PDFs, audio recordings, and videos where possible.
- Run indexing, and record the time taken and the number of chunks.
- Run three to five queries using real questions, and check whether the results are relevant.
- Click the timestamps in video results, and confirm that playback jumps to the correct position.
- Modify one file and run indexing again, and confirm that only that file is re-indexed.
