Skip to content

feat: OpenAI-compatible embedding provider + graceful degradation#1

Merged
iam-dev merged 7 commits intomainfrom
feat/openai-compatible-fallback
Mar 13, 2026
Merged

feat: OpenAI-compatible embedding provider + graceful degradation#1
iam-dev merged 7 commits intomainfrom
feat/openai-compatible-fallback

Conversation

@iam-dev
Copy link
Contributor

@iam-dev iam-dev commented Mar 13, 2026

Summary

  • Add OpenAI-compatible embedding provider (httpx-based) supporting any /v1/embeddings endpoint (Ollama, LM Studio, vLLM, etc.)
  • Graceful degradation: when no embedding provider is available, belief/explain/search fall back to text matching instead of returning 501
  • 100% test coverage + mypy type checking added to CI
  • Refactor working_memory.py to extract commit_frame helpers (fixes pylint R0914)

Changes

  • providers/embeddings/openai_compatible.py — new provider
  • memory.py — auto-detect chain + degraded mode fallback
  • store.py — text-match search when embeddings unavailable
  • working_memory.py — extracted helper methods
  • CI: added mypy step
  • Tests: comprehensive coverage for all new paths

Test plan

  • uv run pytest tests/ -v passes
  • uv run mypy src/mnemebrain_core/ --ignore-missing-imports passes
  • Verify degraded mode works without any embedding provider installed

iam-dev added 4 commits March 10, 2026 20:24
…degradation

Add OpenAICompatibleProvider that works with any OpenAI-compatible
/v1/embeddings endpoint (Ollama, LM Studio, vLLM). Uses httpx (now a
core dependency) with configurable base_url, model, and optional api_key.

Auto-detection order: SentenceTransformers → OpenAI-compatible server
(EMBEDDING_BASE_URL + EMBEDDING_MODEL env vars) → OpenAI API → None.

When no embedder is available, the system runs in degraded mode instead
of raising 501: believe uses exact-match dedup, explain falls back to
exact claim match, search uses case-insensitive substring matching via
new store.find_by_text() method. A warning is logged at init.
- Add mypy to dev deps and fix type errors in store.py (kuzu QueryResult
  union type) by introducing _query() and _next_row() typed helpers
- Fix variable redefinition in memory.py believe() method
- Add dict-payload and string-belief-id tests for working_memory commit
  to cover the two remaining uncovered lines (197, 242)
Add mypy step to the lint job in ci.yml. Move mypy from
dependency-groups to the dev optional-dependency so it's installed
by uv sync --extra dev.
…R0914

- Extract _get, _build_evidence_input, _apply_new_beliefs, _apply_revisions
  from commit_frame to reduce local variables from 18 to under 15
- Add mocked SentenceTransformerProvider tests for 100% coverage
- Pylint score: 10.00/10
m._embedder = None # Force no embedder
with pytest.raises(ImportError, match="No embedding provider"):
m._get_embedder()
import mnemebrain_core.memory as mem_mod
iam-dev added 3 commits March 13, 2026 12:43
- Replace test_get_embedder_raises_when_none with
  test_degraded_mode_when_no_embedder (method was removed in
  degraded-mode refactor)
- Change _build_evidence_input return annotation from "EvidenceInput"
  forward ref to Any to satisfy ruff F821
@github-actions
Copy link

Dependency Review

The following issues were found:
  • ✅ 0 vulnerable package(s)
  • ✅ 0 package(s) with incompatible licenses
  • ✅ 0 package(s) with invalid SPDX license definitions
  • ⚠️ 1 package(s) with unknown licenses.
See the Details below.

License Issues

pyproject.toml

PackageVersionLicenseIssue Type
httpx>= 0.27NullUnknown License

OpenSSF Scorecard

PackageVersionScoreDetails
pip/httpx >= 0.27 UnknownUnknown
pip/librt 0.8.1 UnknownUnknown
pip/mypy 1.19.1 UnknownUnknown
pip/mypy-extensions 1.1.0 UnknownUnknown
pip/pathspec 1.0.4 UnknownUnknown

Scanned Files

  • pyproject.toml
  • uv.lock

@iam-dev iam-dev merged commit 3efd47b into main Mar 13, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant