Semantic Search¶
Semantic Search mode lets users upload text-oriented files, split content into chunks, generate embeddings, and store semantic context in SQLite for later retrieval.
π§ Purpose¶
Semantic Search mode supports local embedding workflows. It converts uploaded text into chunks,
encodes those chunks with the configured sentence-transformer model, and stores the resulting
text/vector pairs in the local SQLite embeddings table.
Semantic context can then be used by the Text Generation pipeline when semantic grounding is enabled.
π§± Workflow Position¶
Upload Files
β
βΌ
Decode Text
β
βΌ
Chunk Text
β
βΌ
Generate Embeddings
β
βΌ
Store Chunks and Vectors in SQLite
β
βΌ
Use Semantic Context in Prompt Builder
π Opening Semantic Search Mode¶
- Start Leeroy.
- Select the sidebar mode:
- Confirm that the Semantic Search page displays the semantic context toggle and upload control.
π₯ Uploading Files¶
Use the upload control to load files for embedding.
The Semantic Search workflow reads uploaded file bytes and attempts to decode them as text. The decoded text is split into overlapping chunks before embedding.
For best results, use files with extractable text content.
| File Content | Expected Behavior |
|---|---|
| Plain text | Best fit for direct decoding and chunking. |
| Markdown | Good fit because text structure is preserved. |
| CSV-like text | Usable if the content is meaningful as text. |
| Binary documents | May not decode usefully in this mode. Use Document Q&A for PDFs. |
π§© Chunking¶
Leeroy uses the shared text chunking helper to split uploaded content into overlapping chunks.
Chunking improves retrieval because it allows the application to compare the userβs prompt against smaller, focused text windows rather than one large document.
| Chunking Feature | Purpose |
|---|---|
| Fixed chunk size | Keeps retrieved context manageable. |
| Overlap | Preserves continuity across chunk boundaries. |
| Ordered chunks | Keeps source text progression intact. |
π§ Embedding¶
Semantic Search uses the local sentence-transformer embedder loaded by the application.
The default model is:
Each chunk is encoded into a vector. Leeroy stores the chunk text and vector bytes in SQLite.
ποΈ SQLite Storage¶
Semantic Search writes to the local embeddings table.
| Column | Purpose |
|---|---|
id |
Row identifier. |
chunk |
Text chunk used as semantic context. |
vector |
Vector representation stored as bytes. |
When a new semantic index is built, the app clears existing embedding rows and writes the new chunk/vector set.
π Semantic Context in Text Generation¶
When semantic context is enabled, the prompt builder can retrieve the most similar stored chunks for a user prompt and inject those chunks into the system context before local model generation.
This lets Text Generation use previously embedded material without manually pasting it into the prompt.
π§ͺ Example Workflow¶
- Open Semantic Search.
- Enable semantic context.
- Upload one or more text files.
- Wait for the semantic index to build.
- Switch to Text Generation.
- Ask a question that relates to the uploaded content.
Example prompt after indexing:
β Recommended Sequence¶
- Use clean, text-based files.
- Build the semantic index before asking related questions.
- Enable semantic context only when the indexed content is relevant.
- Rebuild the index when changing the source material.
- Keep prompts specific enough to retrieve the right chunks.
π§― Troubleshooting¶
| Issue | Likely Cause | Fix |
|---|---|---|
| No semantic index built | No readable text chunks were produced. | Use text-based files or convert binary files to text. |
| Embedding model unavailable | Sentence-transformer model could not load. | Confirm dependencies are installed and internet/model cache availability is adequate. |
| Irrelevant context appears | Indexed content is too broad or unrelated. | Rebuild the index with narrower material. |
| Text Generation ignores context | Semantic context toggle is disabled or retrieval returns weak matches. | Enable semantic context and ask a more specific question. |
π Related API Pages¶
| API Page | Purpose |
|---|---|
| App API | Source documentation for chunking, embedding access, cosine similarity, and prompt construction. |
| Configuration API | Runtime settings and help text used by the semantic workflow. |