Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

19.2 KB
Raw Blame
{% extends "base.html" %}
{% from "components/help_macros.html" import tooltip, help_panel, help_step, help_tip, glossary_term with context %}

{% block title %}Embedding Settings{% endblock %}

{% block extra_head %}<link rel="stylesheet" href="/static/css/embedding_settings.css">{% endblock %}

{% block content %}
<div class="ldr-library-container">
    <div class="ldr-library-header">
        <h1>Default Embedding Settings</h1>
        <p class="ldr-subtitle">Configure default embedding models for new collections and semantic search</p>
    </div>

    <!-- Understanding Embeddings Help Panel -->
    {% call help_panel('embedding-how', 'Understanding Embeddings', icon='brain', collapsed=true, dismissible=true) %}
    <div class="ldr-help-steps">
        {{ help_step(1, "What are Embeddings?", "Embeddings convert text into numbers (vectors) that capture meaning. Similar concepts have similar vectors.") }}
        {{ help_step(2, "Document Chunk Size", "Maximum size of each chunk — characters for the recursive and semantic splitters, tokens for the token and sentence splitters. Larger chunks keep more context per search result but less precision; smaller chunks are more granular but may lose context.") }}
        {{ help_step(3, "Text Splitter", "Recursive: uses natural breaks. Semantic: AI-powered grouping (slower). Token-based: respects LLM limits.") }}
        {{ help_step(4, "Why Lock Settings?", "Mixing different embedding models causes inconsistent search results. Each collection uses one model.") }}
    </div>
    {{ help_tip("<strong>Recommended:</strong> Start with defaults. Only change if you understand the trade-offs.") }}
    {% endcall %}

    <!-- Important Warning -->
    <div class="ldr-alert ldr-alert-warning" style="margin-bottom: 2rem;">
        <div style="display: flex; align-items: flex-start; gap: 1rem;">
            <i aria-hidden="true" class="fas fa-exclamation-triangle" style="font-size: 1.5rem; margin-top: 0.25rem;"></i>
            <div>
                <h4 style="margin: 0 0 0.5rem 0;">Important: Existing Collections</h4>
                <p style="margin: 0 0 0.5rem 0;">
                    <strong>Changing these settings will only affect NEW collections.</strong>
                    Existing collections keep their original embedding settings to ensure data integrity and search consistency.
                </p>
                <p style="margin: 0;">
                    <i aria-hidden="true" class="fas fa-lock"></i> Once a collection is indexed, its embedding settings are locked.
                    To change settings for an existing collection, use Re-Index All Documents to build a replacement index. The current index stays available until the replacement is ready.
                </p>
            </div>
        </div>
    </div>

    <div class="ldr-rag-config-panel">
        <h2>Supported Sentence Transformers models</h2>
        <p class="ldr-text-muted">
            These are the models available directly through the Sentence Transformers provider.
            Indexing a large collection can take a while; keeping the default is fine if the resource use works for you.
            Choose a smaller model if CPU load or memory use interferes with other work.
            Each link opens the model's Hugging Face page with more details.
        </p>
        <ul>
            {% for model_name, model in sentence_transformer_models.items() %}
            <li><a href="https://huggingface.co/{{ model.repository }}" target="_blank" rel="noopener noreferrer">{{ model_name }}</a>{% if model_name == default_sentence_transformer_model %} (default){% endif %}: {{ model.description }} Input limit: {{ model.max_seq_length }} tokens.</li>
            {% endfor %}
        </ul>
        <p class="ldr-form-text ldr-text-muted">
            Models have different input limits; long chunks may be truncated. Review chunk size when switching models.
            For more locally managed model choices, use Ollama.
            <a href="https://github.com/LearningCircuit/local-deep-research/blob/main/docs/embedding-performance.md" target="_blank" rel="noopener noreferrer">Embedding performance guide &#8599;</a>
        </p>
    </div>

    <!-- Test Panel -->
    <div class="ldr-rag-operations-panel">
        <h2><i aria-hidden="true" class="fas fa-vial"></i> Test Configuration</h2>
        <p class="ldr-text-muted" style="margin-bottom: 15px;">
            Test the currently selected embedding model to ensure it's working correctly.
        </p>

        <div class="ldr-alert ldr-alert-info" id="sentence-transformers-download-notice" role="note" style="margin-bottom: 15px;">
            <i aria-hidden="true" class="fas fa-download"></i>
            <strong>Using another Sentence Transformers model?</strong>
            Sentence Transformers models require a one-time download before they can be used offline.
            Temporarily set <strong>Egress Scope</strong> to <strong>Public only</strong>, or use <strong>Adaptive</strong> while it resolves to public
            (a public primary search engine with no private collection selected). If you enabled <strong>Require local embeddings</strong>,
            turn it off for this download. Select the model under Configuration, then click
            <strong>Test Embedding Model</strong>. After the test passes, LDR can reuse the local cache when you return to a more restrictive scope.
            Direct arbitrary Hugging Face model IDs are not downloaded. For a broader choice of locally managed embedding models, we recommend using <strong>Ollama</strong>.
            Change this in <a href="/settings/">Settings &rarr; Search Engines &rarr; Egress Scope</a>.
        </div>

        <div class="ldr-operations-grid">
            <button class="ldr-btn ldr-btn-success ldr-btn-lg" data-ldr-onclick="ldr-4c2b17647c07" data-ldr-template-token="{{ template_event_token }}" id="test-config-btn">
                <i aria-hidden="true" class="fas fa-play"></i> Test Embedding Model
            </button>
        </div>

        <div id="test-result" style="margin-top: 15px; display: none;">
            <!-- Test results will appear here -->
        </div>
    </div>

    <!-- Configuration Panel -->
    <div class="ldr-rag-config-panel">
        <h2><i aria-hidden="true" class="fas fa-cog"></i> Configuration</h2>

        <div class="ldr-config-grid">
            <!-- Saved Default Settings -->
            <div class="ldr-config-section">
                <h3>Saved Default Settings</h3>
                <div id="saved-default-settings" class="ldr-info-box">
                    <div class="ldr-loading-spinner">
                        <i aria-hidden="true" class="fas fa-spinner fa-spin"></i> Loading...
                    </div>
                </div>
                <p class="ldr-form-text ldr-text-muted">
                    <i aria-hidden="true" class="fas fa-info-circle"></i> These are your saved defaults for new collections. Change them using the form below.
                </p>
            </div>

            <!-- Default Embedding Configuration -->
            <div class="ldr-config-section">
                <h3>Default Embedding Configuration</h3>
                <div>
                    <div class="ldr-form-group">
                        <label for="embedding-provider">Provider</label>
                        <select id="embedding-provider" class="ldr-form-control">
                            <option value="">Loading providers...</option>
                        </select>
                    </div>

                    <div class="ldr-form-group" id="ollama-url-group" style="display: none;">
                        <label for="ollama-url">Ollama URL</label>
                        <input type="text" id="ollama-url" class="ldr-form-control" placeholder="http://localhost:11434">
                        <small class="ldr-form-text ldr-text-muted">
                            URL of the Ollama server for embedding models. Leave empty to use the default LLM Ollama URL.
                        </small>
                    </div>

                    <div class="ldr-form-group" id="ollama-num-ctx-group" style="display: none;">
                        <label for="ollama-num-ctx">{{ tooltip("Ollama Context Window (num_ctx)", "Token budget passed to Ollama for each embedding call. If your chunks tokenize to more than this, Ollama returns HTTP 500 and indexing fails. Increase if you see 'input length exceeds the context length'. Default 8192 is safe for chunk sizes up to ~5000 characters.") }}</label>
                        <input type="number" id="ollama-num-ctx" class="ldr-form-control" value="8192" min="512" max="131072" step="512">
                        <small class="ldr-form-text ldr-text-muted">
                            Tokens. Must exceed the largest chunk after tokenization. Increase if Ollama returns "input length exceeds the context length".
                        </small>
                    </div>

                    <div class="ldr-form-group">
                        <label for="embedding-model">Model</label>
                        <select id="embedding-model" class="ldr-form-control">
                            <!-- Options loaded dynamically -->
                        </select>
                        <small class="ldr-form-text ldr-text-muted">
                            <span id="model-description"></span>
                        </small>
                    </div>

                    <div class="ldr-form-group" id="openai-embedding-batch-size-group" hidden>
                        <label for="openai-embedding-batch-size">Embedding Request Batch Size</label>
                        <input type="number" id="openai-embedding-batch-size" class="ldr-form-control"
                            value="5" min="1" step="1" required
                            aria-describedby="openai-embedding-batch-size-help openai-embedding-batch-size-error">
                        <small id="openai-embedding-batch-size-help" class="ldr-form-text ldr-text-muted">
                            Defaults to 5 chunks per request for conservative local compatibility. This controls request batching, not document chunk characters. Cloud OpenAI users may increase it for higher throughput.
                        </small>
                        <div id="openai-embedding-batch-size-error" class="ldr-field-error" aria-live="polite"></div>
                    </div>

                    <div class="ldr-form-row">
                        <div class="ldr-form-group ldr-col-md-6">
                            <label for="chunk-size">{{ tooltip("Document Chunk Size", "Maximum size of each chunk. Larger values keep more context but reduce search precision; smaller values are more granular but may cut off important context.") }}</label>
                            <input type="number" id="chunk-size" class="ldr-form-control" value="{{ local_search_defaults.chunk_size }}" min="100" max="5000" step="100">
                            <small class="ldr-form-text ldr-text-muted">Characters for recursive/semantic; tokens for token and sentence (sentence is capped by the tokenizer's max length).</small>
                        </div>
                        <div class="ldr-form-group ldr-col-md-6">
                            <label for="chunk-overlap">{{ tooltip("Chunk Overlap", "Content shared between adjacent chunks to prevent important info from being cut at boundaries. Usually 10-20% of the chunk size.") }}</label>
                            <input type="number" id="chunk-overlap" class="ldr-form-control" value="{{ local_search_defaults.chunk_overlap }}" min="0" max="1000" step="50">
                            <small class="ldr-form-text ldr-text-muted">Ignored by the semantic splitter (always 0).</small>
                        </div>
                    </div>

                    <div class="ldr-form-row">
                        <div class="ldr-form-group ldr-col-md-6">
                            <label for="splitter-type">{{ tooltip("Text Splitter Type", "Method used to split documents into chunks.") }}</label>
                            <select id="splitter-type" class="ldr-form-control">
                                <option value="recursive" {{ 'selected' if local_search_defaults.splitter_type == 'recursive' else '' }}>Recursive (Default - uses separators)</option> {# nosemgrep: generic.html-templates.security.unquoted-attribute-var.unquoted-attribute-var, reason: Only fixed selected/checked attribute names can be emitted #}
                                <option value="token" {{ 'selected' if local_search_defaults.splitter_type == 'token' else '' }}>Token-based (Good for LLM context)</option> {# nosemgrep: generic.html-templates.security.unquoted-attribute-var.unquoted-attribute-var, reason: Only fixed selected/checked attribute names can be emitted #}
                                <option value="sentence" {{ 'selected' if local_search_defaults.splitter_type == 'sentence' else '' }}>Sentence-based (Clean boundaries)</option> {# nosemgrep: generic.html-templates.security.unquoted-attribute-var.unquoted-attribute-var, reason: Only fixed selected/checked attribute names can be emitted #}
                                <option value="semantic" {{ 'selected' if local_search_defaults.splitter_type == 'semantic' else '' }}>Semantic (Smart grouping - slower)</option> {# nosemgrep: generic.html-templates.security.unquoted-attribute-var.unquoted-attribute-var, reason: Only fixed selected/checked attribute names can be emitted #}
                            </select>
                            <small class="ldr-form-text ldr-text-muted">
                                Recursive and semantic respect text separators; token and sentence ignore them.
                            </small>
                        </div>
                        <div class="ldr-form-group ldr-col-md-6">
                            <label for="distance-metric">Distance Metric</label>
                            <select id="distance-metric" class="ldr-form-control">
                                <option value="cosine" {{ 'selected' if local_search_defaults.distance_metric == 'cosine' else '' }}>Cosine Similarity (Recommended)</option> {# nosemgrep: generic.html-templates.security.unquoted-attribute-var.unquoted-attribute-var, reason: Only fixed selected/checked attribute names can be emitted #}
                                <option value="l2" {{ 'selected' if local_search_defaults.distance_metric == 'l2' else '' }}>Euclidean Distance (L2)</option> {# nosemgrep: generic.html-templates.security.unquoted-attribute-var.unquoted-attribute-var, reason: Only fixed selected/checked attribute names can be emitted #}
                                <option value="dot_product" {{ 'selected' if local_search_defaults.distance_metric == 'dot_product' else '' }}>Dot Product</option> {# nosemgrep: generic.html-templates.security.unquoted-attribute-var.unquoted-attribute-var, reason: Only fixed selected/checked attribute names can be emitted #}
                            </select>
                            <small class="ldr-form-text ldr-text-muted">
                                Cosine similarity recommended for text embeddings
                            </small>
                        </div>
                        <div class="ldr-form-group ldr-col-md-6">
                            <label for="index-type">{{ tooltip("Index Type", "Flat: exact but slow for large collections. HNSW: approximate but 50x faster for >10K docs. IVF: good balance for frequently updated collections.") }}</label>
                            <select id="index-type" class="ldr-form-control">
                                <option value="flat" {{ 'selected' if local_search_defaults.index_type == 'flat' else '' }}>Flat (Exact search, &lt;10K docs)</option> {# nosemgrep: generic.html-templates.security.unquoted-attribute-var.unquoted-attribute-var, reason: Only fixed selected/checked attribute names can be emitted #}
                                <option value="hnsw" {{ 'selected' if local_search_defaults.index_type == 'hnsw' else '' }}>HNSW (Fast, large collections)</option> {# nosemgrep: generic.html-templates.security.unquoted-attribute-var.unquoted-attribute-var, reason: Only fixed selected/checked attribute names can be emitted #}
                                <option value="ivf" {{ 'selected' if local_search_defaults.index_type == 'ivf' else '' }}>IVF (Balanced, updates)</option> {# nosemgrep: generic.html-templates.security.unquoted-attribute-var.unquoted-attribute-var, reason: Only fixed selected/checked attribute names can be emitted #}
                            </select>
                            <small class="ldr-form-text ldr-text-muted">
                                HNSW recommended for &gt;10K documents (50-60× faster)
                            </small>
                        </div>
                    </div>

                    <div class="ldr-form-group">
                        <label>
                            <input type="checkbox" id="normalize-vectors" {{ 'checked' if local_search_defaults.normalize_vectors else '' }}> {# nosemgrep: generic.html-templates.security.unquoted-attribute-var.unquoted-attribute-var, reason: Only fixed selected/checked attribute names can be emitted #}
                            Normalize vectors (L2)
                        </label>
                        <small class="ldr-form-text ldr-text-muted" style="display: block; margin-left: 25px;">
                            <i aria-hidden="true" class="fas fa-info-circle"></i> Recommended: Ensures fair comparison regardless of document length
                        </small>
                    </div>

                    <div class="ldr-form-group">
                        <label for="text-separators">Text Separators (Advanced)</label>
                        <textarea id="text-separators" class="ldr-form-control" rows="3"
                            placeholder='{{ local_search_defaults.text_separators | tojson }}'></textarea>
                        <small class="ldr-form-text ldr-text-muted">
                            JSON array of separators. Default works for 80% of use cases. Used by recursive and semantic splitters only — token and sentence ignore this. For code, add language-specific separators like "\nclass", "\ndef".
                        </small>
                    </div>

                    <small class="ldr-form-text ldr-text-muted ldr-mt-2">
                        <i aria-hidden="true" class="fas fa-info-circle"></i> Changes save automatically. These settings are used as defaults for new collections; existing collections continue using their current settings unless re-indexed.
                    </small>
                </div>
            </div>
        </div>
    </div>

    {% include "components/embedding_performance_hint.html" %}

    <!-- Provider Information Panel -->
    <div class="ldr-rag-stats-panel">
        <h2><i aria-hidden="true" class="fas fa-info-circle"></i> Provider Information</h2>
        <div id="provider-info" class="ldr-stats-grid">
            <div class="ldr-loading-spinner">
                <i aria-hidden="true" class="fas fa-spinner fa-spin"></i> Loading provider information...
            </div>
        </div>
    </div>
</div>

<script defer src="/static/js/embedding_settings.js"></script>
{% endblock %}

{% block page_scripts %}
<script defer src="/static/js/embedding_performance_hint.js"></script>
{% endblock %}