Skip to content

About

Scolta AI search for Django and Wagtail: searchable models, management commands, signal-driven reindexing, optional Amazee.ai LLM tier. Built on the scolta package.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

scolta-django

Scolta AI Search for Django — zero-infrastructure AI-powered search with Pagefind. The Django adapter over the scolta Python binding.

Install & configure

# settings.py
INSTALLED_APPS = [..., "scolta_django"]

SCOLTA = {
    "ai_api_key": env("SCOLTA_API_KEY"),
    # No default. Omit this and AI features stay off; search is unaffected.
    "ai_provider": "anthropic",
    "site_name": "My Site",
    "indexer": "auto",                 # pure-Python indexer (default)
    "models": ["blog.Post", "pages.Page"],   # models using SearchableMixin
    "output_dir": BASE_DIR / "static" / "scolta-pagefind",
    "state_dir": BASE_DIR / ".scolta-state",
    "auto_rebuild": True,              # debounced rebuild on model save/delete
    "auto_rebuild_delay": 300,
    "route_prefix": "api/scolta/v1",

    # Filter sidebar: hide a facet value with no results for the current query,
    # and drop a filter group whose values are all zero. An active (checked)
    # value stays visible so it can be unchecked. Set False to render every
    # value, showing a zero-count one as a disabled "(0)" row.
    "hide_empty_facets": True,

    # Ranking: weight each partial match by how rare its term is in the corpus,
    # so a match on a rare intent-bearing term outranks a match on a ubiquitous
    # one. The defaults below are the browser's own, so omit them unless tuning.
    "specificity_weighting": True,     # False restores flat sub-query weighting
    "specificity_floor": 0.15,         # floor for a ubiquitous term's weight (0-1)
    "specificity_strong_match": 0.55,  # specificity counting as a strong hit (0-1)
    # Co-occurrence: a page agreeing with several query terms outranks one that
    # spikes on a single rare word.
    "specificity_cooccurrence": 0.9,   # bonus multiplier (0-5); 0 disables
    "specificity_agreement_gate": 0.45,   # specificity a term needs to count (0-1)
    "specificity_agreement_decay": 1.0,   # factor per successive agreeing term

    # Search as you type: a suggestions dropdown while someone types. The full
    # search (AI expansion, summary, follow-ups) still runs only on Enter, on the
    # search button, or on picking a suggestion. On by default, and no index
    # rebuild is needed. The defaults below are the browser's own, so omit them
    # unless tuning; sayt_enabled False restores the previous search box exactly.
    "sayt_enabled": True,
    "sayt_min_chars": 2,               # graphemes typed before suggesting; CJK wants 1
    "sayt_debounce_ms": 150,           # typing pause before suggestions are fetched
    "sayt_max_suggestions": 6,         # also the cap on index reads per pass
    "sayt_recent_searches": True,      # the visitor's own, from their browser storage
    "sayt_max_recent": 3,
    "sayt_expand": True,               # enrich suggestions with AI query expansion
    "sayt_expand_per_minute": 6,       # shares the AI budget with committed searches
    "sayt_expansion_delay_ms": 500,    # idle delay before an AI call, longer than above
    "sayt_suggestion_action": "navigate",  # or "search" to run the full search
}

Every core scolta config key is accepted here: the whole SCOLTA dict is handed to ScoltaConfig.from_dict(), which ignores keys it does not recognise. See scolta-python's docs/CONFIG_REFERENCE.md for the full list and defaults.

# urls.py
urlpatterns = [..., path("", include("scolta_django.urls"))]

Make a model searchable:

from scolta_django.searchable import SearchableMixin

class Post(SearchableMixin, models.Model):
    title = models.CharField(max_length=200)
    body = models.TextField()
    # Override for HTML content / custom URLs:
    def to_searchable_content(self):
        from scolta.content import ContentItem
        return ContentItem(id=f"post-{self.pk}", title=self.title,
                           body_html=self.body, url=self.get_absolute_url(),
                           date=self.updated_at.strftime("%Y-%m-%d"))

Build the index and render the widget:

python manage.py scolta_build          # --force --incremental --resume --restart
{% load scolta %}{% scolta_search %}

Static assets

The browser runtime (scolta.js/css, the WASM scoring engine, the Pagefind runtime) is vendored inside the scolta package, where no default staticfiles finder looks. Add the bundled finder so collectstatic (and the dev server) serve it at the default asset_url (/static/scolta/):

STATICFILES_FINDERS = [
    "django.contrib.staticfiles.finders.FileSystemFinder",
    "django.contrib.staticfiles.finders.AppDirectoriesFinder",
    "scolta_django.staticfiles.ScoltaAssetFinder",
]

Settings:

  • SCOLTA["asset_url"] (default /static/scolta/) — base URL the {% scolta_search %} tag uses for the CSS/JS/WASM tags. Point it elsewhere if you serve the bundle from a CDN or copy it yourself.
  • SCOLTA["amazee_access"] (optional) — callable (request) -> bool gating the Amazee.ai settings page and JSON endpoints. Default: active staff user.

Selecting an AI provider is always manual

Scolta ships with no AI provider selected. SCOLTA["ai_provider"] is empty until you set it, and while it is empty AI features are simply off: search works, no provider is assumed, and Anthropic in particular is not silently assumed. There is no default anywhere. This is going-forward only — a project that already sets a provider keeps working exactly as before.

Amazee.ai is never enabled on its own. Setting SCOLTA["ai_provider"] = "amazee" is the manual opt-in, and it is the only thing that permits Scolta to establish the free demo connection on first use — the same act as clicking "Try the demo" in the admin. With the provider unset or set to anything else, no credential is provisioned and no outbound Amazee call is made on any request path. First-use provisioning is idempotent, and an explicit ai_api_key always wins and suppresses Amazee entirely.

In the Amazee.ai settings page there are exactly two actions, and neither runs on its own:

  • Try the demo — one click. No email, no account, no card. Runs until the demo's included credit is used up, and is one-time per site; once used, the page points you at the account path.
  • Enter your Amazee credentials — sign in with the email address on your amazee.ai account. Amazee emails a verification code, you pick a region, and your account's credentials are stored for you. If you do not have an account yet, this creates one. You never generate or paste an API key: this mirrors amazee.ai's own ai_provider_amazeeio module, so there is deliberately no bring-your-own-key form.

When a connection stops being accepted, AI degrades cleanly, /health reports it, and the settings page shows a prompt pointing at the account path. Which of the two actions established the current connection is recorded when it happens rather than inferred afterwards; a connection made before Scolta recorded it claims no origin at all.

Health endpoint

GET /api/scolta/v1/health always answers monitoring tools: anonymous requests get {"status": "ok"} (or "degraded"), HTTP 200. The full diagnostic payload (AI provider, configured flags, index state) requires an active staff user — the same bar as staff_member_required, without the login redirect that would break uptime monitors.

Wagtail

If Wagtail is installed, the optional scolta_django.wagtail module is loaded automatically (StreamField extraction, page-tree enumeration, admin panel). Indexing Wagtail pages is opt-in: set SCOLTA["wagtail"] = True to use the Wagtail content source, which indexes live public pages alongside the configured models. With the flag unset, only SCOLTA["models"] are indexed (the admin panel and signal wiring load either way).

Development

uv venv --python 3.12 && uv pip install -e ".[dev]"
uv run pytest

About

Scolta AI search for Django and Wagtail: searchable models, management commands, signal-driven reindexing, optional Amazee.ai LLM tier. Built on the scolta package.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages