mdcontext 0.0.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.changeset/README.md +28 -0
- package/.changeset/config.json +11 -0
- package/.claude/settings.local.json +25 -0
- package/.github/workflows/ci.yml +83 -0
- package/.github/workflows/claude-code-review.yml +44 -0
- package/.github/workflows/claude.yml +85 -0
- package/.github/workflows/release.yml +113 -0
- package/.tldrignore +112 -0
- package/BACKLOG.md +338 -0
- package/CONTRIBUTING.md +186 -0
- package/NOTES/NOTES +44 -0
- package/README.md +434 -11
- package/biome.json +36 -0
- package/cspell.config.yaml +14 -0
- package/dist/chunk-23UPXDNL.js +3044 -0
- package/dist/chunk-2W7MO2DL.js +1366 -0
- package/dist/chunk-3NUAZGMA.js +1689 -0
- package/dist/chunk-7TOWB2XB.js +366 -0
- package/dist/chunk-7XOTOADQ.js +3065 -0
- package/dist/chunk-AH2PDM2K.js +3042 -0
- package/dist/chunk-BNXWSZ63.js +3742 -0
- package/dist/chunk-BTL5DJVU.js +3222 -0
- package/dist/chunk-HDHYG7E4.js +104 -0
- package/dist/chunk-HLR4KZBP.js +3234 -0
- package/dist/chunk-IP3FRFEB.js +1045 -0
- package/dist/chunk-KHU56VDO.js +3042 -0
- package/dist/chunk-KRYIFLQR.js +88 -0
- package/dist/chunk-LBSDNLEM.js +287 -0
- package/dist/chunk-MNTQ7HCP.js +2643 -0
- package/dist/chunk-MUJELQQ6.js +1387 -0
- package/dist/chunk-MXJGMSLV.js +2199 -0
- package/dist/chunk-N6QJGC3Z.js +2636 -0
- package/dist/chunk-OBELGBPM.js +1713 -0
- package/dist/chunk-OT7R5XTA.js +3192 -0
- package/dist/chunk-P7X4RA2T.js +106 -0
- package/dist/chunk-PIDUQNC2.js +3185 -0
- package/dist/chunk-POGCDIH4.js +3187 -0
- package/dist/chunk-PSIEOQGZ.js +3043 -0
- package/dist/chunk-PVRT3IHA.js +3238 -0
- package/dist/chunk-QNN4TT23.js +1430 -0
- package/dist/chunk-RE3R45RJ.js +3042 -0
- package/dist/chunk-S7E6TFX6.js +803 -0
- package/dist/chunk-SG6GLU4U.js +1378 -0
- package/dist/chunk-SJCDV2ST.js +274 -0
- package/dist/chunk-SYE5XLF3.js +104 -0
- package/dist/chunk-T5VLYBZD.js +103 -0
- package/dist/chunk-TOQB7VWU.js +3238 -0
- package/dist/chunk-VFNMZ4ZQ.js +3228 -0
- package/dist/chunk-VVTGZNBT.js +1629 -0
- package/dist/chunk-W7Q4RFEV.js +104 -0
- package/dist/chunk-XTYYVRLO.js +3190 -0
- package/dist/chunk-Y6MDYVJD.js +3063 -0
- package/dist/cli/main.d.ts +1 -0
- package/dist/cli/main.js +5458 -0
- package/dist/index.d.ts +653 -0
- package/dist/index.js +79 -0
- package/dist/mcp/server.d.ts +1 -0
- package/dist/mcp/server.js +472 -0
- package/dist/schema-BAWSG7KY.js +22 -0
- package/dist/schema-E3QUPL26.js +20 -0
- package/dist/schema-EHL7WUT6.js +20 -0
- package/docs/019-USAGE.md +625 -0
- package/docs/020-current-implementation.md +364 -0
- package/docs/021-DOGFOODING-FINDINGS.md +175 -0
- package/docs/BACKLOG.md +80 -0
- package/docs/CONFIG.md +1123 -0
- package/docs/DESIGN.md +439 -0
- package/docs/ERRORS.md +383 -0
- package/docs/PROJECT.md +88 -0
- package/docs/ROADMAP.md +407 -0
- package/docs/summarization.md +320 -0
- package/docs/test-links.md +9 -0
- package/justfile +40 -0
- package/package.json +74 -9
- package/pnpm-workspace.yaml +5 -0
- package/research/INDEX.md +315 -0
- package/research/code-review/README.md +90 -0
- package/research/code-review/cli-error-handling-review.md +979 -0
- package/research/code-review/code-review-validation-report.md +464 -0
- package/research/code-review/main-ts-review.md +1128 -0
- package/research/config-analysis/01-current-implementation.md +470 -0
- package/research/config-analysis/02-strategy-recommendation.md +428 -0
- package/research/config-analysis/03-task-candidates.md +715 -0
- package/research/config-analysis/033-research-configuration-management.md +828 -0
- package/research/config-analysis/034-research-effect-cli-config.md +1504 -0
- package/research/config-analysis/04-consolidated-task-candidates.md +277 -0
- package/research/config-docs/SUMMARY.md +357 -0
- package/research/config-docs/TEST-RESULTS.md +776 -0
- package/research/config-docs/TODO.md +542 -0
- package/research/config-docs/analysis.md +744 -0
- package/research/config-docs/fix-validation.md +502 -0
- package/research/config-docs/help-audit.md +264 -0
- package/research/config-docs/help-system-analysis.md +890 -0
- package/research/dogfood/consolidated-tool-evaluation.md +373 -0
- package/research/dogfood/strategy-a/a-synthesis.md +184 -0
- package/research/dogfood/strategy-a/a1-docs.md +226 -0
- package/research/dogfood/strategy-a/a2-amorphic.md +156 -0
- package/research/dogfood/strategy-a/a3-llm.md +164 -0
- package/research/dogfood/strategy-b/b-synthesis.md +228 -0
- package/research/dogfood/strategy-b/b1-architecture.md +207 -0
- package/research/dogfood/strategy-b/b2-gaps.md +258 -0
- package/research/dogfood/strategy-b/b3-workflows.md +250 -0
- package/research/dogfood/strategy-c/c-synthesis.md +451 -0
- package/research/dogfood/strategy-c/c1-explorer.md +192 -0
- package/research/dogfood/strategy-c/c2-diver-memory.md +145 -0
- package/research/dogfood/strategy-c/c3-diver-control.md +148 -0
- package/research/dogfood/strategy-c/c4-diver-failure.md +151 -0
- package/research/dogfood/strategy-c/c5-diver-execution.md +221 -0
- package/research/dogfood/strategy-c/c6-diver-org.md +221 -0
- package/research/effect-cli-error-handling.md +845 -0
- package/research/effect-errors-as-values.md +943 -0
- package/research/errors-task-analysis/00-consolidated-tasks.md +207 -0
- package/research/errors-task-analysis/cli-commands-analysis.md +909 -0
- package/research/errors-task-analysis/embeddings-analysis.md +709 -0
- package/research/errors-task-analysis/index-search-analysis.md +812 -0
- package/research/frontmatter/COMMENTS-ARE-SKIPPED.md +149 -0
- package/research/frontmatter/LLM-CODE-NAVIGATION.md +276 -0
- package/research/issue-review.md +603 -0
- package/research/llm-summarization/agent-cli-tools-2026.md +1082 -0
- package/research/llm-summarization/alternative-providers-2026.md +1428 -0
- package/research/llm-summarization/anthropic-2026.md +367 -0
- package/research/llm-summarization/claude-cli-integration.md +1706 -0
- package/research/llm-summarization/cli-integration-patterns.md +3155 -0
- package/research/llm-summarization/openai-2026.md +473 -0
- package/research/llm-summarization/openai-compatible-providers-2026.md +1022 -0
- package/research/llm-summarization/opencode-cli-integration.md +1552 -0
- package/research/llm-summarization/prompt-engineering-2026.md +1426 -0
- package/research/llm-summarization/prototype-results.md +56 -0
- package/research/llm-summarization/provider-switching-patterns-2026.md +2153 -0
- package/research/llm-summarization/typescript-llm-libraries-2026.md +2436 -0
- package/research/mdcontext-error-analysis.md +521 -0
- package/research/mdcontext-pudding/00-EXECUTIVE-SUMMARY.md +282 -0
- package/research/mdcontext-pudding/01-index-embed.md +956 -0
- package/research/mdcontext-pudding/02-search-COMMANDS.md +142 -0
- package/research/mdcontext-pudding/02-search-SUMMARY.md +146 -0
- package/research/mdcontext-pudding/02-search.md +970 -0
- package/research/mdcontext-pudding/03-context.md +779 -0
- package/research/mdcontext-pudding/04-navigation-and-analytics.md +803 -0
- package/research/mdcontext-pudding/04-tree.md +704 -0
- package/research/mdcontext-pudding/05-config.md +1038 -0
- package/research/mdcontext-pudding/06-links-summary.txt +87 -0
- package/research/mdcontext-pudding/06-links.md +679 -0
- package/research/mdcontext-pudding/07-stats.md +693 -0
- package/research/mdcontext-pudding/BUG-FIX-PLAN.md +388 -0
- package/research/mdcontext-pudding/P0-BUG-VALIDATION.md +167 -0
- package/research/mdcontext-pudding/README.md +168 -0
- package/research/mdcontext-pudding/TESTING-SUMMARY.md +128 -0
- package/research/npm_publish/011-npm-workflow-research-agent2.md +792 -0
- package/research/npm_publish/012-npm-workflow-research-agent1.md +530 -0
- package/research/npm_publish/013-npm-workflow-research-agent3.md +722 -0
- package/research/npm_publish/014-npm-workflow-synthesis.md +556 -0
- package/research/npm_publish/031-npm-workflow-task-analysis.md +134 -0
- package/research/research-quality-review.md +834 -0
- package/research/semantic-search/002-research-embedding-models.md +490 -0
- package/research/semantic-search/003-research-rag-alternatives.md +523 -0
- package/research/semantic-search/004-research-vector-search.md +841 -0
- package/research/semantic-search/032-research-semantic-search.md +427 -0
- package/research/semantic-search/embedding-text-analysis.md +156 -0
- package/research/semantic-search/multi-word-failure-reproduction.md +171 -0
- package/research/semantic-search/query-processing-analysis.md +207 -0
- package/research/semantic-search/root-cause-and-solution.md +114 -0
- package/research/semantic-search/threshold-validation-report.md +69 -0
- package/research/semantic-search/vector-search-analysis.md +63 -0
- package/research/task-management-2026/00-synthesis-recommendations.md +295 -0
- package/research/task-management-2026/01-ai-workflow-tools.md +416 -0
- package/research/task-management-2026/02-agent-framework-patterns.md +476 -0
- package/research/task-management-2026/03-lightweight-file-based.md +567 -0
- package/research/task-management-2026/04-established-tools-ai-features.md +541 -0
- package/research/task-management-2026/linear/01-core-features-workflow.md +771 -0
- package/research/task-management-2026/linear/02-api-integrations.md +930 -0
- package/research/task-management-2026/linear/03-ai-features.md +368 -0
- package/research/task-management-2026/linear/04-pricing-setup.md +205 -0
- package/research/task-management-2026/linear/05-usage-patterns-best-practices.md +605 -0
- package/research/test-path-issues.md +276 -0
- package/review/ALP-76/1-error-type-design.md +962 -0
- package/review/ALP-76/2-error-handling-patterns.md +906 -0
- package/review/ALP-76/3-error-presentation.md +624 -0
- package/review/ALP-76/4-test-coverage.md +625 -0
- package/review/ALP-76/5-migration-completeness.md +440 -0
- package/review/ALP-76/6-effect-best-practices.md +755 -0
- package/scripts/apply-branch-protection.sh +47 -0
- package/scripts/branch-protection-templates.json +79 -0
- package/scripts/prototype-summarization.ts +346 -0
- package/scripts/rebuild-hnswlib.js +58 -0
- package/scripts/setup-branch-protection.sh +64 -0
- package/src/__tests__/fixtures/semantic-search/multi-word-corpus/.mdcontext/active-provider.json +7 -0
- package/src/__tests__/fixtures/semantic-search/multi-word-corpus/.mdcontext/bm25.json +541 -0
- package/src/__tests__/fixtures/semantic-search/multi-word-corpus/.mdcontext/bm25.meta.json +5 -0
- package/src/__tests__/fixtures/semantic-search/multi-word-corpus/.mdcontext/config.json +8 -0
- package/src/__tests__/fixtures/semantic-search/multi-word-corpus/.mdcontext/embeddings/openai_text-embedding-3-small_512/vectors.bin +0 -0
- package/src/__tests__/fixtures/semantic-search/multi-word-corpus/.mdcontext/embeddings/openai_text-embedding-3-small_512/vectors.meta.bin +0 -0
- package/src/__tests__/fixtures/semantic-search/multi-word-corpus/.mdcontext/indexes/documents.json +60 -0
- package/src/__tests__/fixtures/semantic-search/multi-word-corpus/.mdcontext/indexes/links.json +13 -0
- package/src/__tests__/fixtures/semantic-search/multi-word-corpus/.mdcontext/indexes/sections.json +1197 -0
- package/src/__tests__/fixtures/semantic-search/multi-word-corpus/configuration-management.md +99 -0
- package/src/__tests__/fixtures/semantic-search/multi-word-corpus/distributed-systems.md +92 -0
- package/src/__tests__/fixtures/semantic-search/multi-word-corpus/error-handling.md +78 -0
- package/src/__tests__/fixtures/semantic-search/multi-word-corpus/failure-automation.md +55 -0
- package/src/__tests__/fixtures/semantic-search/multi-word-corpus/job-context.md +69 -0
- package/src/__tests__/fixtures/semantic-search/multi-word-corpus/process-orchestration.md +99 -0
- package/src/cli/argv-preprocessor.test.ts +210 -0
- package/src/cli/argv-preprocessor.ts +202 -0
- package/src/cli/cli.test.ts +627 -0
- package/src/cli/commands/backlinks.ts +54 -0
- package/src/cli/commands/config-cmd.ts +642 -0
- package/src/cli/commands/context.ts +285 -0
- package/src/cli/commands/duplicates.ts +122 -0
- package/src/cli/commands/embeddings.ts +529 -0
- package/src/cli/commands/index-cmd.ts +480 -0
- package/src/cli/commands/index.ts +16 -0
- package/src/cli/commands/links.ts +52 -0
- package/src/cli/commands/search.ts +1281 -0
- package/src/cli/commands/stats.ts +149 -0
- package/src/cli/commands/tree.ts +128 -0
- package/src/cli/config-layer.ts +176 -0
- package/src/cli/error-handler.test.ts +235 -0
- package/src/cli/error-handler.ts +655 -0
- package/src/cli/flag-schemas.ts +341 -0
- package/src/cli/help.ts +588 -0
- package/src/cli/index.ts +9 -0
- package/src/cli/main.ts +435 -0
- package/src/cli/options.ts +41 -0
- package/src/cli/shared-error-handling.ts +199 -0
- package/src/cli/typo-suggester.test.ts +105 -0
- package/src/cli/typo-suggester.ts +130 -0
- package/src/cli/utils.ts +259 -0
- package/src/config/file-provider.test.ts +320 -0
- package/src/config/file-provider.ts +273 -0
- package/src/config/index.ts +72 -0
- package/src/config/integration.test.ts +667 -0
- package/src/config/precedence.test.ts +277 -0
- package/src/config/precedence.ts +451 -0
- package/src/config/schema.test.ts +414 -0
- package/src/config/schema.ts +603 -0
- package/src/config/service.test.ts +320 -0
- package/src/config/service.ts +243 -0
- package/src/config/testing.test.ts +264 -0
- package/src/config/testing.ts +110 -0
- package/src/core/index.ts +1 -0
- package/src/core/types.ts +113 -0
- package/src/duplicates/detector.test.ts +183 -0
- package/src/duplicates/detector.ts +414 -0
- package/src/duplicates/index.ts +18 -0
- package/src/embeddings/embedding-namespace.test.ts +300 -0
- package/src/embeddings/embedding-namespace.ts +947 -0
- package/src/embeddings/heading-boost.test.ts +222 -0
- package/src/embeddings/hnsw-build-options.test.ts +198 -0
- package/src/embeddings/hyde.test.ts +272 -0
- package/src/embeddings/hyde.ts +264 -0
- package/src/embeddings/index.ts +10 -0
- package/src/embeddings/openai-provider.ts +414 -0
- package/src/embeddings/pricing.json +22 -0
- package/src/embeddings/provider-constants.ts +204 -0
- package/src/embeddings/provider-errors.test.ts +967 -0
- package/src/embeddings/provider-errors.ts +565 -0
- package/src/embeddings/provider-factory.test.ts +240 -0
- package/src/embeddings/provider-factory.ts +225 -0
- package/src/embeddings/provider-integration.test.ts +788 -0
- package/src/embeddings/query-preprocessing.test.ts +187 -0
- package/src/embeddings/semantic-search-threshold.test.ts +508 -0
- package/src/embeddings/semantic-search.ts +1270 -0
- package/src/embeddings/types.ts +359 -0
- package/src/embeddings/vector-store.ts +708 -0
- package/src/embeddings/voyage-provider.ts +313 -0
- package/src/errors/errors.test.ts +845 -0
- package/src/errors/index.ts +533 -0
- package/src/index/ignore-patterns.test.ts +354 -0
- package/src/index/ignore-patterns.ts +305 -0
- package/src/index/index.ts +4 -0
- package/src/index/indexer.ts +684 -0
- package/src/index/storage.ts +260 -0
- package/src/index/types.ts +147 -0
- package/src/index/watcher.ts +189 -0
- package/src/index.ts +30 -0
- package/src/integration/search-keyword.test.ts +678 -0
- package/src/mcp/server.ts +612 -0
- package/src/parser/index.ts +1 -0
- package/src/parser/parser.test.ts +291 -0
- package/src/parser/parser.ts +394 -0
- package/src/parser/section-filter.test.ts +277 -0
- package/src/parser/section-filter.ts +392 -0
- package/src/search/__tests__/hybrid-search.test.ts +650 -0
- package/src/search/bm25-store.ts +366 -0
- package/src/search/cross-encoder.test.ts +253 -0
- package/src/search/cross-encoder.ts +406 -0
- package/src/search/fuzzy-search.test.ts +419 -0
- package/src/search/fuzzy-search.ts +273 -0
- package/src/search/hybrid-search.ts +448 -0
- package/src/search/path-matcher.test.ts +276 -0
- package/src/search/path-matcher.ts +33 -0
- package/src/search/query-parser.test.ts +260 -0
- package/src/search/query-parser.ts +319 -0
- package/src/search/searcher.test.ts +280 -0
- package/src/search/searcher.ts +724 -0
- package/src/search/wink-bm25.d.ts +30 -0
- package/src/summarization/cli-providers/claude.ts +202 -0
- package/src/summarization/cli-providers/detection.test.ts +273 -0
- package/src/summarization/cli-providers/detection.ts +118 -0
- package/src/summarization/cli-providers/index.ts +8 -0
- package/src/summarization/cost.test.ts +139 -0
- package/src/summarization/cost.ts +102 -0
- package/src/summarization/error-handler.test.ts +127 -0
- package/src/summarization/error-handler.ts +111 -0
- package/src/summarization/index.ts +102 -0
- package/src/summarization/pipeline.test.ts +498 -0
- package/src/summarization/pipeline.ts +231 -0
- package/src/summarization/prompts.test.ts +269 -0
- package/src/summarization/prompts.ts +133 -0
- package/src/summarization/provider-factory.test.ts +396 -0
- package/src/summarization/provider-factory.ts +178 -0
- package/src/summarization/types.ts +184 -0
- package/src/summarize/budget-bugs.test.ts +620 -0
- package/src/summarize/formatters.ts +419 -0
- package/src/summarize/index.ts +20 -0
- package/src/summarize/summarizer.test.ts +275 -0
- package/src/summarize/summarizer.ts +597 -0
- package/src/summarize/verify-bugs.test.ts +238 -0
- package/src/types/huggingface-transformers.d.ts +66 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/tokens.test.ts +142 -0
- package/src/utils/tokens.ts +186 -0
- package/tests/fixtures/cli/.mdcontext/active-provider.json +7 -0
- package/tests/fixtures/cli/.mdcontext/config.json +8 -0
- package/tests/fixtures/cli/.mdcontext/embeddings/openai_text-embedding-3-small_512/vectors.bin +0 -0
- package/tests/fixtures/cli/.mdcontext/embeddings/openai_text-embedding-3-small_512/vectors.meta.bin +0 -0
- package/tests/fixtures/cli/.mdcontext/indexes/documents.json +33 -0
- package/tests/fixtures/cli/.mdcontext/indexes/links.json +12 -0
- package/tests/fixtures/cli/.mdcontext/indexes/sections.json +247 -0
- package/tests/fixtures/cli/README.md +9 -0
- package/tests/fixtures/cli/api-reference.md +11 -0
- package/tests/fixtures/cli/getting-started.md +11 -0
- package/tests/integration/embed-index.test.ts +712 -0
- package/tests/integration/search-context.test.ts +469 -0
- package/tests/integration/search-semantic.test.ts +522 -0
- package/tsconfig.json +26 -0
- package/vitest.config.ts +16 -0
- package/vitest.setup.ts +12 -0
package/docs/CONFIG.md
ADDED
|
@@ -0,0 +1,1123 @@
|
|
|
1
|
+
# Configuration Guide
|
|
2
|
+
|
|
3
|
+
mdcontext supports a layered configuration system that allows you to set persistent defaults, override them with environment variables, and use CLI flags for one-off changes.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Quick Start](#quick-start)
|
|
8
|
+
- [Configuration Precedence](#configuration-precedence)
|
|
9
|
+
- [Config File Formats](#config-file-formats)
|
|
10
|
+
- [Configuration Options](#configuration-options)
|
|
11
|
+
- [Index Configuration](#index-configuration)
|
|
12
|
+
- [Search Configuration](#search-configuration)
|
|
13
|
+
- [Embeddings Configuration](#embeddings-configuration)
|
|
14
|
+
- [Summarization Configuration](#summarization-configuration)
|
|
15
|
+
- [AI Summarization Configuration](#ai-summarization-configuration)
|
|
16
|
+
- [Output Configuration](#output-configuration)
|
|
17
|
+
- [Paths Configuration](#paths-configuration)
|
|
18
|
+
- [Environment Variables](#environment-variables)
|
|
19
|
+
- [CLI Commands](#cli-commands)
|
|
20
|
+
- [Migration Guide](#migration-guide)
|
|
21
|
+
- [Testing Configuration](#testing-configuration)
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
Create a config file in your project root:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# Generate a JavaScript config with type annotations (recommended)
|
|
31
|
+
mdcontext config init
|
|
32
|
+
|
|
33
|
+
# Or generate a JSON config
|
|
34
|
+
mdcontext config init --format json
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
This creates `mdcontext.config.js` with documented defaults:
|
|
38
|
+
|
|
39
|
+
```javascript
|
|
40
|
+
/** @type {import('mdcontext').PartialMdContextConfig} */
|
|
41
|
+
export default {
|
|
42
|
+
index: {
|
|
43
|
+
maxDepth: 10,
|
|
44
|
+
excludePatterns: ['node_modules', '.git', 'dist', 'build'],
|
|
45
|
+
},
|
|
46
|
+
search: {
|
|
47
|
+
defaultLimit: 10,
|
|
48
|
+
minSimilarity: 0.35,
|
|
49
|
+
},
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Configuration Precedence
|
|
56
|
+
|
|
57
|
+
mdcontext uses a layered configuration system. Values from higher-priority sources override lower ones:
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
CLI Flags (highest priority)
|
|
61
|
+
|
|
|
62
|
+
Environment Variables
|
|
63
|
+
|
|
|
64
|
+
Config File
|
|
65
|
+
|
|
|
66
|
+
Built-in Defaults (lowest priority)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**Example:**
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# Config file sets: index.maxDepth = 10
|
|
73
|
+
# Environment sets: MDCONTEXT_INDEX_MAXDEPTH = 5
|
|
74
|
+
# CLI flag: --max-depth 3
|
|
75
|
+
|
|
76
|
+
# Effective value: 3 (CLI wins)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## Config File Formats
|
|
82
|
+
|
|
83
|
+
mdcontext searches for configuration files in this order:
|
|
84
|
+
|
|
85
|
+
| Filename | Format | Notes |
|
|
86
|
+
| ------------------------- | ---------- | ----------------------------- |
|
|
87
|
+
| `mdcontext.config.js` | JavaScript | Best: type-safe with JSDoc |
|
|
88
|
+
| `mdcontext.config.mjs` | ESM | ES modules only |
|
|
89
|
+
| `mdcontext.config.json` | JSON | Simple, no code |
|
|
90
|
+
| `.mdcontextrc` | JSON | Hidden file, JSON format |
|
|
91
|
+
| `.mdcontextrc.json` | JSON | Explicit JSON rc file |
|
|
92
|
+
| `mdcontext.config.ts` | TypeScript | Not supported (see note below)|
|
|
93
|
+
|
|
94
|
+
### JavaScript Config with Types (Recommended)
|
|
95
|
+
|
|
96
|
+
Using JSDoc type annotations provides full type safety and IDE autocompletion:
|
|
97
|
+
|
|
98
|
+
```javascript
|
|
99
|
+
// mdcontext.config.js
|
|
100
|
+
/** @type {import('mdcontext').PartialMdContextConfig} */
|
|
101
|
+
export default {
|
|
102
|
+
index: {
|
|
103
|
+
maxDepth: 10,
|
|
104
|
+
excludePatterns: ['node_modules', '.git', 'dist', 'build'],
|
|
105
|
+
fileExtensions: ['.md', '.mdx'],
|
|
106
|
+
followSymlinks: false,
|
|
107
|
+
indexDir: '.mdcontext',
|
|
108
|
+
},
|
|
109
|
+
search: {
|
|
110
|
+
defaultLimit: 10,
|
|
111
|
+
maxLimit: 100,
|
|
112
|
+
minSimilarity: 0.35,
|
|
113
|
+
includeSnippets: true,
|
|
114
|
+
snippetLength: 200,
|
|
115
|
+
},
|
|
116
|
+
embeddings: {
|
|
117
|
+
provider: 'openai',
|
|
118
|
+
model: 'text-embedding-3-small',
|
|
119
|
+
batchSize: 100,
|
|
120
|
+
maxRetries: 3,
|
|
121
|
+
},
|
|
122
|
+
output: {
|
|
123
|
+
format: 'text',
|
|
124
|
+
color: true,
|
|
125
|
+
verbose: false,
|
|
126
|
+
},
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
The `@type` JSDoc annotation provides TypeScript type checking and IDE autocompletion while remaining a valid JavaScript file that Node.js can import directly.
|
|
131
|
+
|
|
132
|
+
**Note:** TypeScript (`.ts`) config files are not currently supported because Node.js cannot import them without a loader. Use JavaScript with JSDoc types instead.
|
|
133
|
+
|
|
134
|
+
### JSON Config
|
|
135
|
+
|
|
136
|
+
```json
|
|
137
|
+
{
|
|
138
|
+
"$schema": "https://mdcontext.dev/schema.json",
|
|
139
|
+
"index": {
|
|
140
|
+
"maxDepth": 10,
|
|
141
|
+
"excludePatterns": ["node_modules", ".git", "dist", "build"],
|
|
142
|
+
"fileExtensions": [".md", ".mdx"]
|
|
143
|
+
},
|
|
144
|
+
"search": {
|
|
145
|
+
"defaultLimit": 10,
|
|
146
|
+
"minSimilarity": 0.35
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Using a Custom Config Path
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
# Use a specific config file
|
|
155
|
+
mdcontext --config ./config/mdcontext.json index
|
|
156
|
+
|
|
157
|
+
# Short form
|
|
158
|
+
mdcontext -c ./custom.config.json search "query"
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## Configuration Options
|
|
164
|
+
|
|
165
|
+
### Index Configuration
|
|
166
|
+
|
|
167
|
+
Controls how markdown files are discovered and indexed.
|
|
168
|
+
|
|
169
|
+
| Option | Type | Default | Description |
|
|
170
|
+
| ----------------- | ---------- | ------------------------------------------ | ---------------------------------------- |
|
|
171
|
+
| `maxDepth` | `number` | `10` | Maximum directory depth to traverse |
|
|
172
|
+
| `excludePatterns` | `string[]` | `['node_modules', '.git', 'dist', 'build']` | Glob patterns to exclude from indexing |
|
|
173
|
+
| `fileExtensions` | `string[]` | `['.md', '.mdx']` | File extensions to index |
|
|
174
|
+
| `followSymlinks` | `boolean` | `false` | Whether to follow symbolic links |
|
|
175
|
+
| `indexDir` | `string` | `'.mdcontext'` | Directory for storing index files |
|
|
176
|
+
|
|
177
|
+
**Example:**
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
export default defineConfig({
|
|
181
|
+
index: {
|
|
182
|
+
// Only index top 5 levels of directories
|
|
183
|
+
maxDepth: 5,
|
|
184
|
+
|
|
185
|
+
// Exclude additional directories
|
|
186
|
+
excludePatterns: [
|
|
187
|
+
'node_modules',
|
|
188
|
+
'.git',
|
|
189
|
+
'dist',
|
|
190
|
+
'build',
|
|
191
|
+
'vendor',
|
|
192
|
+
'__tests__',
|
|
193
|
+
],
|
|
194
|
+
|
|
195
|
+
// Only index standard markdown
|
|
196
|
+
fileExtensions: ['.md'],
|
|
197
|
+
|
|
198
|
+
// Store index in a custom location
|
|
199
|
+
indexDir: '.cache/mdcontext',
|
|
200
|
+
},
|
|
201
|
+
})
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Excluding Files
|
|
205
|
+
|
|
206
|
+
mdcontext automatically respects standard ignore patterns.
|
|
207
|
+
|
|
208
|
+
#### .gitignore (Honored by Default)
|
|
209
|
+
|
|
210
|
+
Your existing `.gitignore` is automatically respected. No additional configuration needed.
|
|
211
|
+
|
|
212
|
+
#### .mdcontextignore (Custom Patterns)
|
|
213
|
+
|
|
214
|
+
Create `.mdcontextignore` in your project root for mdcontext-specific exclusions:
|
|
215
|
+
|
|
216
|
+
```gitignore
|
|
217
|
+
# Ignore research notes
|
|
218
|
+
research/**/*.md
|
|
219
|
+
|
|
220
|
+
# But keep summaries
|
|
221
|
+
!research/**/summary.md
|
|
222
|
+
|
|
223
|
+
# Ignore draft content
|
|
224
|
+
drafts/
|
|
225
|
+
*.draft.md
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
#### Precedence
|
|
229
|
+
|
|
230
|
+
Patterns are applied in this order (later patterns override earlier):
|
|
231
|
+
|
|
232
|
+
1. **Built-in defaults** - `node_modules`, `.git`, `dist`, `build`
|
|
233
|
+
2. **.gitignore** - Standard git ignore patterns
|
|
234
|
+
3. **.mdcontextignore** - mdcontext-specific patterns
|
|
235
|
+
4. **CLI --exclude** - Highest priority, overrides all
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
# Add patterns via CLI (highest priority)
|
|
239
|
+
mdcontext index --exclude "*.draft.md,research/**"
|
|
240
|
+
|
|
241
|
+
# Disable .gitignore honoring
|
|
242
|
+
mdcontext index --no-gitignore
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
#### Pattern Syntax
|
|
246
|
+
|
|
247
|
+
Uses standard `.gitignore` syntax:
|
|
248
|
+
|
|
249
|
+
| Pattern | Matches |
|
|
250
|
+
| ------- | ------- |
|
|
251
|
+
| `*.log` | All .log files |
|
|
252
|
+
| `temp/` | Directory named temp |
|
|
253
|
+
| `**/node_modules/**` | node_modules anywhere |
|
|
254
|
+
| `!important.md` | Negation - include this file |
|
|
255
|
+
| `#comment` | Comments are ignored |
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
### Search Configuration
|
|
260
|
+
|
|
261
|
+
Controls search behavior and defaults.
|
|
262
|
+
|
|
263
|
+
| Option | Type | Default | Description |
|
|
264
|
+
| ------------------- | --------- | ------- | ------------------------------------------------ |
|
|
265
|
+
| `defaultLimit` | `number` | `10` | Default number of search results |
|
|
266
|
+
| `maxLimit` | `number` | `100` | Maximum allowed search results |
|
|
267
|
+
| `minSimilarity` | `number` | `0.35` | Minimum similarity score (0-1) for semantic search |
|
|
268
|
+
| `includeSnippets` | `boolean` | `true` | Include content snippets in results |
|
|
269
|
+
| `snippetLength` | `number` | `200` | Maximum snippet length in characters |
|
|
270
|
+
| `autoIndexThreshold`| `number` | `10` | Auto-create semantic index if under this many seconds |
|
|
271
|
+
|
|
272
|
+
**Example:**
|
|
273
|
+
|
|
274
|
+
```typescript
|
|
275
|
+
export default defineConfig({
|
|
276
|
+
search: {
|
|
277
|
+
// Return more results by default
|
|
278
|
+
defaultLimit: 20,
|
|
279
|
+
|
|
280
|
+
// Require higher similarity for matches
|
|
281
|
+
minSimilarity: 0.7,
|
|
282
|
+
|
|
283
|
+
// Longer snippets for more context
|
|
284
|
+
snippetLength: 300,
|
|
285
|
+
},
|
|
286
|
+
})
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### Embeddings Configuration
|
|
290
|
+
|
|
291
|
+
Controls semantic search embedding generation.
|
|
292
|
+
|
|
293
|
+
| Option | Type | Default | Description |
|
|
294
|
+
| -------------- | -------- | -------------------------- | ---------------------------------------- |
|
|
295
|
+
| `provider` | `string` | `'openai'` | Embedding provider (openai, ollama, lm-studio, openrouter) |
|
|
296
|
+
| `model` | `string` | `'text-embedding-3-small'` | Embedding model name |
|
|
297
|
+
| `dimensions` | `number` | (auto) | Vector dimensions (auto-detected from model if not set) |
|
|
298
|
+
| `batchSize` | `number` | `100` | Batch size for API calls |
|
|
299
|
+
| `maxRetries` | `number` | `3` | Maximum retries for failed API calls |
|
|
300
|
+
| `retryDelayMs` | `number` | `1000` | Delay between retries in milliseconds |
|
|
301
|
+
| `timeoutMs` | `number` | `30000` | Request timeout in milliseconds |
|
|
302
|
+
| `apiKey` | `string` | (from env) | API key (prefer environment variable) |
|
|
303
|
+
|
|
304
|
+
**Model Dimensions:**
|
|
305
|
+
|
|
306
|
+
Dimensions are now automatically configured based on the model. If not explicitly set:
|
|
307
|
+
- **OpenAI text-embedding-3-small/large**: Uses 512 dimensions (Matryoshka reduction for speed)
|
|
308
|
+
- **Ollama nomic-embed-text**: Uses 768 native dimensions
|
|
309
|
+
- **Ollama mxbai-embed-large/bge-m3**: Uses 1024 native dimensions
|
|
310
|
+
|
|
311
|
+
You can override dimensions for models that support Matryoshka reduction:
|
|
312
|
+
```javascript
|
|
313
|
+
embeddings: {
|
|
314
|
+
model: 'text-embedding-3-small',
|
|
315
|
+
dimensions: 1024 // Higher accuracy, larger index
|
|
316
|
+
}
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
**Available Models:**
|
|
320
|
+
|
|
321
|
+
| Model | Native Dims | Default Dims | Matryoshka | Notes |
|
|
322
|
+
| -------------------------- | ----------- | ------------ | ---------- | ----- |
|
|
323
|
+
| `text-embedding-3-small` | 1536 | 512 | Yes | OpenAI, recommended |
|
|
324
|
+
| `text-embedding-3-large` | 3072 | 512 | Yes | OpenAI, highest quality |
|
|
325
|
+
| `text-embedding-ada-002` | 1536 | 1536 | No | OpenAI, legacy |
|
|
326
|
+
| `nomic-embed-text` | 768 | 768 | No | Ollama, recommended for local |
|
|
327
|
+
| `mxbai-embed-large` | 1024 | 1024 | No | Ollama, higher quality |
|
|
328
|
+
| `bge-m3` | 1024 | 1024 | No | Ollama, multilingual |
|
|
329
|
+
|
|
330
|
+
**Example:**
|
|
331
|
+
|
|
332
|
+
```typescript
|
|
333
|
+
export default defineConfig({
|
|
334
|
+
embeddings: {
|
|
335
|
+
// Use higher quality model
|
|
336
|
+
model: 'text-embedding-3-large',
|
|
337
|
+
|
|
338
|
+
// Smaller batches for rate limiting
|
|
339
|
+
batchSize: 50,
|
|
340
|
+
|
|
341
|
+
// More aggressive retries
|
|
342
|
+
maxRetries: 5,
|
|
343
|
+
retryDelayMs: 2000,
|
|
344
|
+
},
|
|
345
|
+
})
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
---
|
|
349
|
+
|
|
350
|
+
## Embedding Providers
|
|
351
|
+
|
|
352
|
+
mdcontext supports multiple embedding providers:
|
|
353
|
+
|
|
354
|
+
| Provider | Best For | Cost | Privacy | Production Ready |
|
|
355
|
+
|----------|----------|------|---------|------------------|
|
|
356
|
+
| **OpenAI** | Production, high quality | $0.02/1M tokens | Cloud | ✓ |
|
|
357
|
+
| **Ollama** | Zero cost, privacy | Free | Local | ✓ |
|
|
358
|
+
| **LM Studio** | Interactive testing | Free | Local | Development only |
|
|
359
|
+
| **OpenRouter** | Multi-model access | ~$0.021/1M tokens | Cloud | ✓ |
|
|
360
|
+
|
|
361
|
+
### Provider Setup
|
|
362
|
+
|
|
363
|
+
**OpenAI (Default):** `export OPENAI_API_KEY=sk-...`
|
|
364
|
+
|
|
365
|
+
**Ollama:** `ollama serve && ollama pull nomic-embed-text`
|
|
366
|
+
|
|
367
|
+
**LM Studio:** Open GUI, load model, start local server
|
|
368
|
+
|
|
369
|
+
**OpenRouter:** `export OPENROUTER_API_KEY=sk-or-v1-...`
|
|
370
|
+
|
|
371
|
+
### Security Considerations
|
|
372
|
+
|
|
373
|
+
**Custom Base URLs**: When using `--provider-base-url` or setting a custom `baseURL` in configuration:
|
|
374
|
+
|
|
375
|
+
⚠️ **Only use trusted sources** - Your API keys and markdown content will be sent to this endpoint.
|
|
376
|
+
|
|
377
|
+
- For Ollama/LM Studio: Only use `localhost` or servers you control
|
|
378
|
+
- For remote Ollama instances: Use encrypted connections (https://) and trusted networks
|
|
379
|
+
- Never point to unknown or untrusted servers
|
|
380
|
+
|
|
381
|
+
**Example safe configurations:**
|
|
382
|
+
```bash
|
|
383
|
+
# Safe: Local Ollama
|
|
384
|
+
mdcontext index --embed --provider-base-url http://localhost:11434/v1
|
|
385
|
+
|
|
386
|
+
# Safe: Trusted internal server with encryption
|
|
387
|
+
mdcontext index --embed --provider-base-url https://ollama.internal.company.com/v1
|
|
388
|
+
|
|
389
|
+
# Unsafe: Unknown external server
|
|
390
|
+
mdcontext index --embed --provider-base-url http://random-server.example.com/v1 # ❌ DON'T DO THIS
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
### CLI Usage
|
|
394
|
+
|
|
395
|
+
```bash
|
|
396
|
+
mdcontext index --embed --provider ollama --provider-model nomic-embed-text
|
|
397
|
+
mdcontext index --embed --provider openrouter
|
|
398
|
+
mdcontext index --embed --provider lm-studio
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
### Configuration
|
|
402
|
+
|
|
403
|
+
```javascript
|
|
404
|
+
export default {
|
|
405
|
+
embeddings: {
|
|
406
|
+
provider: 'ollama',
|
|
407
|
+
model: 'nomic-embed-text',
|
|
408
|
+
},
|
|
409
|
+
}
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
**Note:** Re-indexing required when switching providers.
|
|
413
|
+
|
|
414
|
+
---
|
|
415
|
+
|
|
416
|
+
### Summarization Configuration
|
|
417
|
+
|
|
418
|
+
Controls context assembly and summarization behavior.
|
|
419
|
+
|
|
420
|
+
| Option | Type | Default | Description |
|
|
421
|
+
| ------------------- | -------- | ------- | ------------------------------------------ |
|
|
422
|
+
| `briefTokenBudget` | `number` | `100` | Token budget for 'brief' compression level |
|
|
423
|
+
| `summaryTokenBudget`| `number` | `500` | Token budget for 'summary' compression level |
|
|
424
|
+
| `compressionRatio` | `number` | `0.3` | Target compression ratio (0-1) |
|
|
425
|
+
| `minSectionTokens` | `number` | `20` | Minimum tokens for any section summary |
|
|
426
|
+
| `maxTopics` | `number` | `10` | Maximum topics to extract from a document |
|
|
427
|
+
| `minPartialBudget` | `number` | `50` | Minimum remaining budget for partial content |
|
|
428
|
+
|
|
429
|
+
**Example:**
|
|
430
|
+
|
|
431
|
+
```typescript
|
|
432
|
+
export default defineConfig({
|
|
433
|
+
summarization: {
|
|
434
|
+
// More detailed brief summaries
|
|
435
|
+
briefTokenBudget: 150,
|
|
436
|
+
|
|
437
|
+
// Higher compression for large docs
|
|
438
|
+
compressionRatio: 0.2,
|
|
439
|
+
},
|
|
440
|
+
})
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
### AI Summarization Configuration
|
|
444
|
+
|
|
445
|
+
Controls AI-powered summarization of search results. This is separate from `summarization` which handles token budgets for context assembly.
|
|
446
|
+
|
|
447
|
+
| Option | Type | Default | Description |
|
|
448
|
+
| ---------- | -------- | ---------- | ---------------------------------------------- |
|
|
449
|
+
| `mode` | `string` | `'cli'` | `'cli'` (free) or `'api'` (pay-per-use) |
|
|
450
|
+
| `provider` | `string` | `'claude'` | Provider name (see tables below) |
|
|
451
|
+
| `model` | `string` | (optional) | Model name for API providers |
|
|
452
|
+
| `stream` | `boolean`| `false` | Enable streaming output |
|
|
453
|
+
| `baseURL` | `string` | (optional) | Custom API base URL |
|
|
454
|
+
| `apiKey` | `string` | (from env) | API key (prefer environment variable) |
|
|
455
|
+
|
|
456
|
+
**CLI Providers (FREE with subscription):**
|
|
457
|
+
|
|
458
|
+
| Provider | Config Value | Requires |
|
|
459
|
+
|----------|--------------|----------|
|
|
460
|
+
| Claude Code | `'claude'` | Claude Pro/Team subscription |
|
|
461
|
+
| GitHub Copilot | `'copilot'` | Copilot subscription |
|
|
462
|
+
| OpenCode | `'opencode'` | BYOK configuration |
|
|
463
|
+
| Aider | `'aider'` | Model configuration |
|
|
464
|
+
| Cline | `'cline'` | Model configuration |
|
|
465
|
+
|
|
466
|
+
**API Providers (pay-per-use):**
|
|
467
|
+
|
|
468
|
+
| Provider | Config Value | Cost per 1M tokens | API Key Env Var |
|
|
469
|
+
|----------|--------------|-------------------|-----------------|
|
|
470
|
+
| DeepSeek | `'deepseek'` | $0.14-0.56 | `DEEPSEEK_API_KEY` |
|
|
471
|
+
| Qwen | `'qwen'` | $0.03-0.12 | `QWEN_API_KEY` |
|
|
472
|
+
| Google Gemini | `'gemini'` | $0.30-2.50 | `GOOGLE_API_KEY` |
|
|
473
|
+
| OpenAI GPT | `'openai'` | $1.75-14.00 | `OPENAI_API_KEY` |
|
|
474
|
+
| Anthropic Claude | `'anthropic'` | $3.00-15.00 | `ANTHROPIC_API_KEY` |
|
|
475
|
+
|
|
476
|
+
**Example:**
|
|
477
|
+
|
|
478
|
+
```javascript
|
|
479
|
+
// mdcontext.config.js
|
|
480
|
+
/** @type {import('mdcontext').PartialMdContextConfig} */
|
|
481
|
+
export default {
|
|
482
|
+
aiSummarization: {
|
|
483
|
+
// Use Claude CLI (free with subscription)
|
|
484
|
+
mode: 'cli',
|
|
485
|
+
provider: 'claude',
|
|
486
|
+
},
|
|
487
|
+
}
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
**Example with API provider:**
|
|
491
|
+
|
|
492
|
+
```javascript
|
|
493
|
+
export default {
|
|
494
|
+
aiSummarization: {
|
|
495
|
+
// Use DeepSeek API (ultra-cheap)
|
|
496
|
+
mode: 'api',
|
|
497
|
+
provider: 'deepseek',
|
|
498
|
+
model: 'deepseek-chat',
|
|
499
|
+
},
|
|
500
|
+
}
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
See [docs/summarization.md](./summarization.md) for architecture details and adding new providers.
|
|
504
|
+
|
|
505
|
+
### Output Configuration
|
|
506
|
+
|
|
507
|
+
Controls CLI output formatting.
|
|
508
|
+
|
|
509
|
+
| Option | Type | Default | Description |
|
|
510
|
+
| ------------ | ------------------- | -------- | ------------------------------ |
|
|
511
|
+
| `format` | `'text'` \| `'json'`| `'text'` | Default output format |
|
|
512
|
+
| `color` | `boolean` | `true` | Use colors in terminal output |
|
|
513
|
+
| `prettyJson` | `boolean` | `true` | Pretty-print JSON output |
|
|
514
|
+
| `verbose` | `boolean` | `false` | Show verbose output |
|
|
515
|
+
| `debug` | `boolean` | `false` | Show debug information |
|
|
516
|
+
|
|
517
|
+
**Example:**
|
|
518
|
+
|
|
519
|
+
```typescript
|
|
520
|
+
export default defineConfig({
|
|
521
|
+
output: {
|
|
522
|
+
// Always output JSON for scripting
|
|
523
|
+
format: 'json',
|
|
524
|
+
prettyJson: true,
|
|
525
|
+
|
|
526
|
+
// Disable colors for CI environments
|
|
527
|
+
color: false,
|
|
528
|
+
},
|
|
529
|
+
})
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
### Paths Configuration
|
|
533
|
+
|
|
534
|
+
Controls file path behavior.
|
|
535
|
+
|
|
536
|
+
| Option | Type | Default | Description |
|
|
537
|
+
| ------------ | -------- | -------------------- | ------------------------------ |
|
|
538
|
+
| `root` | `string` | (current directory) | Root directory for markdown files |
|
|
539
|
+
| `configFile` | `string` | (auto-detected) | Custom config file path |
|
|
540
|
+
| `cacheDir` | `string` | `'.mdcontext/cache'` | Cache directory for temporary files |
|
|
541
|
+
|
|
542
|
+
**Example:**
|
|
543
|
+
|
|
544
|
+
```typescript
|
|
545
|
+
export default defineConfig({
|
|
546
|
+
paths: {
|
|
547
|
+
// Index a specific subdirectory
|
|
548
|
+
root: './docs',
|
|
549
|
+
|
|
550
|
+
// Custom cache location
|
|
551
|
+
cacheDir: '.cache/mdcontext',
|
|
552
|
+
},
|
|
553
|
+
})
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
---
|
|
557
|
+
|
|
558
|
+
## Environment Variables
|
|
559
|
+
|
|
560
|
+
All configuration options can be set via environment variables using the `MDCONTEXT_` prefix.
|
|
561
|
+
|
|
562
|
+
### Variable Naming
|
|
563
|
+
|
|
564
|
+
Convert the config key to uppercase and replace dots with underscores:
|
|
565
|
+
|
|
566
|
+
```
|
|
567
|
+
config key: index.maxDepth
|
|
568
|
+
environment var: MDCONTEXT_INDEX_MAXDEPTH
|
|
569
|
+
```
|
|
570
|
+
|
|
571
|
+
### Complete Variable Reference
|
|
572
|
+
|
|
573
|
+
#### Index Configuration
|
|
574
|
+
|
|
575
|
+
| Variable | Config Key |
|
|
576
|
+
| --------------------------------- | ------------------------ |
|
|
577
|
+
| `MDCONTEXT_INDEX_MAXDEPTH` | `index.maxDepth` |
|
|
578
|
+
| `MDCONTEXT_INDEX_EXCLUDEPATTERNS` | `index.excludePatterns` |
|
|
579
|
+
| `MDCONTEXT_INDEX_FILEEXTENSIONS` | `index.fileExtensions` |
|
|
580
|
+
| `MDCONTEXT_INDEX_FOLLOWSYMLINKS` | `index.followSymlinks` |
|
|
581
|
+
| `MDCONTEXT_INDEX_INDEXDIR` | `index.indexDir` |
|
|
582
|
+
|
|
583
|
+
#### Search Configuration
|
|
584
|
+
|
|
585
|
+
| Variable | Config Key |
|
|
586
|
+
| ----------------------------------- | ------------------------- |
|
|
587
|
+
| `MDCONTEXT_SEARCH_DEFAULTLIMIT` | `search.defaultLimit` |
|
|
588
|
+
| `MDCONTEXT_SEARCH_MAXLIMIT` | `search.maxLimit` |
|
|
589
|
+
| `MDCONTEXT_SEARCH_MINSIMILARITY` | `search.minSimilarity` |
|
|
590
|
+
| `MDCONTEXT_SEARCH_INCLUDESNIPPETS` | `search.includeSnippets` |
|
|
591
|
+
| `MDCONTEXT_SEARCH_SNIPPETLENGTH` | `search.snippetLength` |
|
|
592
|
+
| `MDCONTEXT_SEARCH_AUTOINDEXTHRESHOLD` | `search.autoIndexThreshold` |
|
|
593
|
+
|
|
594
|
+
#### Embeddings Configuration
|
|
595
|
+
|
|
596
|
+
| Variable | Config Key |
|
|
597
|
+
| --------------------------------- | ------------------------ |
|
|
598
|
+
| `MDCONTEXT_EMBEDDINGS_PROVIDER` | `embeddings.provider` |
|
|
599
|
+
| `MDCONTEXT_EMBEDDINGS_MODEL` | `embeddings.model` |
|
|
600
|
+
| `MDCONTEXT_EMBEDDINGS_DIMENSIONS` | `embeddings.dimensions` |
|
|
601
|
+
| `MDCONTEXT_EMBEDDINGS_BATCHSIZE` | `embeddings.batchSize` |
|
|
602
|
+
| `MDCONTEXT_EMBEDDINGS_MAXRETRIES` | `embeddings.maxRetries` |
|
|
603
|
+
| `MDCONTEXT_EMBEDDINGS_RETRYDELAYMS` | `embeddings.retryDelayMs` |
|
|
604
|
+
| `MDCONTEXT_EMBEDDINGS_TIMEOUTMS` | `embeddings.timeoutMs` |
|
|
605
|
+
| `MDCONTEXT_EMBEDDINGS_APIKEY` | `embeddings.apiKey` |
|
|
606
|
+
|
|
607
|
+
#### Summarization Configuration
|
|
608
|
+
|
|
609
|
+
| Variable | Config Key |
|
|
610
|
+
| ------------------------------------------ | -------------------------------- |
|
|
611
|
+
| `MDCONTEXT_SUMMARIZATION_BRIEFTOKENBUDGET` | `summarization.briefTokenBudget` |
|
|
612
|
+
| `MDCONTEXT_SUMMARIZATION_SUMMARYTOKENBUDGET` | `summarization.summaryTokenBudget` |
|
|
613
|
+
| `MDCONTEXT_SUMMARIZATION_COMPRESSIONRATIO` | `summarization.compressionRatio` |
|
|
614
|
+
| `MDCONTEXT_SUMMARIZATION_MINSECTIONTOKENS` | `summarization.minSectionTokens` |
|
|
615
|
+
| `MDCONTEXT_SUMMARIZATION_MAXTOPICS` | `summarization.maxTopics` |
|
|
616
|
+
| `MDCONTEXT_SUMMARIZATION_MINPARTIALBUDGET` | `summarization.minPartialBudget` |
|
|
617
|
+
|
|
618
|
+
#### AI Summarization Configuration
|
|
619
|
+
|
|
620
|
+
| Variable | Config Key |
|
|
621
|
+
| --------------------------------------- | --------------------------- |
|
|
622
|
+
| `MDCONTEXT_AISUMMARIZATION_MODE` | `aiSummarization.mode` |
|
|
623
|
+
| `MDCONTEXT_AISUMMARIZATION_PROVIDER` | `aiSummarization.provider` |
|
|
624
|
+
| `MDCONTEXT_AISUMMARIZATION_MODEL` | `aiSummarization.model` |
|
|
625
|
+
| `MDCONTEXT_AISUMMARIZATION_STREAM` | `aiSummarization.stream` |
|
|
626
|
+
| `MDCONTEXT_AISUMMARIZATION_BASEURL` | `aiSummarization.baseURL` |
|
|
627
|
+
| `MDCONTEXT_AISUMMARIZATION_APIKEY` | `aiSummarization.apiKey` |
|
|
628
|
+
|
|
629
|
+
**Note:** For API providers, also set the provider-specific API key environment variable:
|
|
630
|
+
- `DEEPSEEK_API_KEY`, `ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, `GOOGLE_API_KEY`, `QWEN_API_KEY`
|
|
631
|
+
|
|
632
|
+
#### Output Configuration
|
|
633
|
+
|
|
634
|
+
| Variable | Config Key |
|
|
635
|
+
| ------------------------------- | ------------------- |
|
|
636
|
+
| `MDCONTEXT_OUTPUT_FORMAT` | `output.format` |
|
|
637
|
+
| `MDCONTEXT_OUTPUT_COLOR` | `output.color` |
|
|
638
|
+
| `MDCONTEXT_OUTPUT_PRETTYJSON` | `output.prettyJson` |
|
|
639
|
+
| `MDCONTEXT_OUTPUT_VERBOSE` | `output.verbose` |
|
|
640
|
+
| `MDCONTEXT_OUTPUT_DEBUG` | `output.debug` |
|
|
641
|
+
|
|
642
|
+
#### Paths Configuration
|
|
643
|
+
|
|
644
|
+
| Variable | Config Key |
|
|
645
|
+
| ----------------------------- | ------------------ |
|
|
646
|
+
| `MDCONTEXT_PATHS_ROOT` | `paths.root` |
|
|
647
|
+
| `MDCONTEXT_PATHS_CONFIGFILE` | `paths.configFile` |
|
|
648
|
+
| `MDCONTEXT_PATHS_CACHEDIR` | `paths.cacheDir` |
|
|
649
|
+
|
|
650
|
+
### Array Values
|
|
651
|
+
|
|
652
|
+
For array values, use comma-separated strings:
|
|
653
|
+
|
|
654
|
+
```bash
|
|
655
|
+
export MDCONTEXT_INDEX_EXCLUDEPATTERNS="node_modules,.git,dist,vendor"
|
|
656
|
+
export MDCONTEXT_INDEX_FILEEXTENSIONS=".md,.mdx,.markdown"
|
|
657
|
+
```
|
|
658
|
+
|
|
659
|
+
### Boolean Values
|
|
660
|
+
|
|
661
|
+
Use `true` or `false`:
|
|
662
|
+
|
|
663
|
+
```bash
|
|
664
|
+
export MDCONTEXT_INDEX_FOLLOWSYMLINKS=true
|
|
665
|
+
export MDCONTEXT_OUTPUT_COLOR=false
|
|
666
|
+
```
|
|
667
|
+
|
|
668
|
+
### Example: CI Environment
|
|
669
|
+
|
|
670
|
+
```bash
|
|
671
|
+
# .github/workflows/docs.yml
|
|
672
|
+
env:
|
|
673
|
+
MDCONTEXT_OUTPUT_COLOR: 'false'
|
|
674
|
+
MDCONTEXT_OUTPUT_FORMAT: 'json'
|
|
675
|
+
MDCONTEXT_SEARCH_DEFAULTLIMIT: '50'
|
|
676
|
+
```
|
|
677
|
+
|
|
678
|
+
---
|
|
679
|
+
|
|
680
|
+
## CLI Commands
|
|
681
|
+
|
|
682
|
+
### config init
|
|
683
|
+
|
|
684
|
+
Create a starter configuration file.
|
|
685
|
+
|
|
686
|
+
```bash
|
|
687
|
+
mdcontext config init [options]
|
|
688
|
+
|
|
689
|
+
Options:
|
|
690
|
+
-f, --format <ts|json> Config file format (default: ts)
|
|
691
|
+
--force Overwrite existing config file
|
|
692
|
+
--json Output as JSON
|
|
693
|
+
--pretty Pretty-print JSON output
|
|
694
|
+
```
|
|
695
|
+
|
|
696
|
+
**Examples:**
|
|
697
|
+
|
|
698
|
+
```bash
|
|
699
|
+
# Create TypeScript config
|
|
700
|
+
mdcontext config init
|
|
701
|
+
|
|
702
|
+
# Create JSON config
|
|
703
|
+
mdcontext config init --format json
|
|
704
|
+
|
|
705
|
+
# Overwrite existing config
|
|
706
|
+
mdcontext config init --force
|
|
707
|
+
```
|
|
708
|
+
|
|
709
|
+
### config show
|
|
710
|
+
|
|
711
|
+
Display the current config file location.
|
|
712
|
+
|
|
713
|
+
```bash
|
|
714
|
+
mdcontext config show [options]
|
|
715
|
+
|
|
716
|
+
Options:
|
|
717
|
+
--json Output as JSON
|
|
718
|
+
--pretty Pretty-print JSON output
|
|
719
|
+
```
|
|
720
|
+
|
|
721
|
+
### config check
|
|
722
|
+
|
|
723
|
+
Validate configuration and show effective values with their sources.
|
|
724
|
+
|
|
725
|
+
```bash
|
|
726
|
+
mdcontext config check [options]
|
|
727
|
+
|
|
728
|
+
Options:
|
|
729
|
+
--json Output as JSON
|
|
730
|
+
--pretty Pretty-print JSON output
|
|
731
|
+
```
|
|
732
|
+
|
|
733
|
+
**Example output:**
|
|
734
|
+
|
|
735
|
+
```
|
|
736
|
+
Configuration validated successfully!
|
|
737
|
+
|
|
738
|
+
Source: /project/mdcontext.config.ts
|
|
739
|
+
|
|
740
|
+
Effective configuration:
|
|
741
|
+
index:
|
|
742
|
+
maxDepth: 10 (from config file)
|
|
743
|
+
excludePatterns: ["node_modules",".git","dist"] (default)
|
|
744
|
+
fileExtensions: [".md",".mdx"] (default)
|
|
745
|
+
followSymlinks: false (default)
|
|
746
|
+
indexDir: .mdcontext (default)
|
|
747
|
+
search:
|
|
748
|
+
defaultLimit: 20 (from environment)
|
|
749
|
+
maxLimit: 100 (default)
|
|
750
|
+
minSimilarity: 0.35 (default)
|
|
751
|
+
...
|
|
752
|
+
```
|
|
753
|
+
|
|
754
|
+
---
|
|
755
|
+
|
|
756
|
+
## Migration Guide
|
|
757
|
+
|
|
758
|
+
### From CLI-Only Usage
|
|
759
|
+
|
|
760
|
+
If you've been passing flags on every command:
|
|
761
|
+
|
|
762
|
+
```bash
|
|
763
|
+
# Before: Flags every time
|
|
764
|
+
mdcontext index --exclude vendor --exclude __tests__
|
|
765
|
+
mdcontext search "query" --limit 20
|
|
766
|
+
```
|
|
767
|
+
|
|
768
|
+
Create a config file to persist these settings:
|
|
769
|
+
|
|
770
|
+
```bash
|
|
771
|
+
# Generate config
|
|
772
|
+
mdcontext config init
|
|
773
|
+
```
|
|
774
|
+
|
|
775
|
+
Edit `mdcontext.config.ts`:
|
|
776
|
+
|
|
777
|
+
```typescript
|
|
778
|
+
import { defineConfig } from 'mdcontext'
|
|
779
|
+
|
|
780
|
+
export default defineConfig({
|
|
781
|
+
index: {
|
|
782
|
+
excludePatterns: ['node_modules', '.git', 'dist', 'build', 'vendor', '__tests__'],
|
|
783
|
+
},
|
|
784
|
+
search: {
|
|
785
|
+
defaultLimit: 20,
|
|
786
|
+
},
|
|
787
|
+
})
|
|
788
|
+
```
|
|
789
|
+
|
|
790
|
+
Now commands use your defaults:
|
|
791
|
+
|
|
792
|
+
```bash
|
|
793
|
+
# After: Clean commands
|
|
794
|
+
mdcontext index
|
|
795
|
+
mdcontext search "query"
|
|
796
|
+
|
|
797
|
+
# Override when needed
|
|
798
|
+
mdcontext search "query" --limit 5
|
|
799
|
+
```
|
|
800
|
+
|
|
801
|
+
### From Environment Variables
|
|
802
|
+
|
|
803
|
+
If you've been setting environment variables:
|
|
804
|
+
|
|
805
|
+
```bash
|
|
806
|
+
# .bashrc or .zshrc
|
|
807
|
+
export OPENAI_API_KEY=sk-...
|
|
808
|
+
export MDCONTEXT_SEARCH_DEFAULTLIMIT=20
|
|
809
|
+
```
|
|
810
|
+
|
|
811
|
+
You can now move project-specific settings to a config file while keeping environment variables for:
|
|
812
|
+
|
|
813
|
+
- Secrets (API keys)
|
|
814
|
+
- Machine-specific settings
|
|
815
|
+
- CI/CD overrides
|
|
816
|
+
|
|
817
|
+
---
|
|
818
|
+
|
|
819
|
+
## Testing Configuration
|
|
820
|
+
|
|
821
|
+
mdcontext provides utilities for testing with custom configurations.
|
|
822
|
+
|
|
823
|
+
### Test Utilities
|
|
824
|
+
|
|
825
|
+
```typescript
|
|
826
|
+
import { TestConfigLayer, withTestConfig, runWithConfig } from 'mdcontext'
|
|
827
|
+
import { Effect } from 'effect'
|
|
828
|
+
|
|
829
|
+
// Option 1: Use TestConfigLayer directly
|
|
830
|
+
const testEffect = myEffect.pipe(
|
|
831
|
+
Effect.provide(TestConfigLayer)
|
|
832
|
+
)
|
|
833
|
+
|
|
834
|
+
// Option 2: withTestConfig for partial overrides
|
|
835
|
+
const testEffect = myEffect.pipe(
|
|
836
|
+
withTestConfig({
|
|
837
|
+
search: { defaultLimit: 5 }
|
|
838
|
+
})
|
|
839
|
+
)
|
|
840
|
+
|
|
841
|
+
// Option 3: runWithConfig for full test isolation
|
|
842
|
+
const result = await runWithConfig(
|
|
843
|
+
myEffect,
|
|
844
|
+
{ search: { defaultLimit: 5 } }
|
|
845
|
+
)
|
|
846
|
+
```
|
|
847
|
+
|
|
848
|
+
### Isolating Tests from Environment
|
|
849
|
+
|
|
850
|
+
```typescript
|
|
851
|
+
import { createTestConfigProvider } from 'mdcontext'
|
|
852
|
+
|
|
853
|
+
// Creates a provider that ignores environment variables
|
|
854
|
+
const provider = createTestConfigProvider(
|
|
855
|
+
{ search: { defaultLimit: 5 } }, // CLI overrides
|
|
856
|
+
{ index: { maxDepth: 3 } } // File config
|
|
857
|
+
)
|
|
858
|
+
|
|
859
|
+
const effect = myEffect.pipe(
|
|
860
|
+
Effect.withConfigProvider(provider)
|
|
861
|
+
)
|
|
862
|
+
```
|
|
863
|
+
|
|
864
|
+
---
|
|
865
|
+
|
|
866
|
+
## Troubleshooting
|
|
867
|
+
|
|
868
|
+
### Config File Not Loading
|
|
869
|
+
|
|
870
|
+
If your config file isn't being used:
|
|
871
|
+
|
|
872
|
+
1. **Verify the file is found:**
|
|
873
|
+
```bash
|
|
874
|
+
mdcontext config show
|
|
875
|
+
```
|
|
876
|
+
This shows which config file mdcontext is using, if any.
|
|
877
|
+
|
|
878
|
+
2. **Check for errors:**
|
|
879
|
+
```bash
|
|
880
|
+
mdcontext config check --json
|
|
881
|
+
```
|
|
882
|
+
The `errors` array will show any loading failures.
|
|
883
|
+
|
|
884
|
+
3. **Common issues:**
|
|
885
|
+
- **JSON syntax errors:** Validate your JSON with `jq` or an online validator
|
|
886
|
+
- **TypeScript files:** Not currently supported - use `.js` or `.json` instead (see below)
|
|
887
|
+
- **Wrong export:** Ensure `.js` files use `export default { ... }`
|
|
888
|
+
- **File location:** Config must be in project root or parent directory
|
|
889
|
+
|
|
890
|
+
### TypeScript Config Files
|
|
891
|
+
|
|
892
|
+
**Current Limitation:** `.ts` config files are not supported because Node.js cannot import TypeScript directly without a loader.
|
|
893
|
+
|
|
894
|
+
**Recommended Alternatives:**
|
|
895
|
+
|
|
896
|
+
1. **JavaScript with JSDoc types** (recommended):
|
|
897
|
+
```javascript
|
|
898
|
+
// mdcontext.config.js
|
|
899
|
+
/** @type {import('mdcontext').PartialMdContextConfig} */
|
|
900
|
+
export default {
|
|
901
|
+
index: {
|
|
902
|
+
maxDepth: 10,
|
|
903
|
+
},
|
|
904
|
+
}
|
|
905
|
+
```
|
|
906
|
+
This provides full type checking and IDE autocompletion while working at runtime.
|
|
907
|
+
|
|
908
|
+
2. **JSON format** (simplest):
|
|
909
|
+
```bash
|
|
910
|
+
mdcontext config init --format json
|
|
911
|
+
```
|
|
912
|
+
|
|
913
|
+
### Environment Variables Not Working
|
|
914
|
+
|
|
915
|
+
1. **Check variable name:** Must be uppercase with `MDCONTEXT_` prefix
|
|
916
|
+
```bash
|
|
917
|
+
# Correct
|
|
918
|
+
export MDCONTEXT_SEARCH_DEFAULTLIMIT=20
|
|
919
|
+
|
|
920
|
+
# Wrong - will not work
|
|
921
|
+
export mdcontext_search_defaultLimit=20
|
|
922
|
+
```
|
|
923
|
+
|
|
924
|
+
2. **Verify with config check:**
|
|
925
|
+
```bash
|
|
926
|
+
mdcontext config check
|
|
927
|
+
```
|
|
928
|
+
Look for "(from environment)" annotations.
|
|
929
|
+
|
|
930
|
+
3. **Array values:** Use comma-separated strings
|
|
931
|
+
```bash
|
|
932
|
+
export MDCONTEXT_INDEX_EXCLUDEPATTERNS="node_modules,.git,dist"
|
|
933
|
+
```
|
|
934
|
+
|
|
935
|
+
### Config Not Taking Effect
|
|
936
|
+
|
|
937
|
+
If you've set config but commands still use defaults:
|
|
938
|
+
|
|
939
|
+
1. **Check precedence:** CLI flags override everything
|
|
940
|
+
```bash
|
|
941
|
+
# This ignores config file's defaultLimit setting
|
|
942
|
+
mdcontext search "query" --limit 5
|
|
943
|
+
```
|
|
944
|
+
|
|
945
|
+
2. **Verify effective config:**
|
|
946
|
+
```bash
|
|
947
|
+
mdcontext config check
|
|
948
|
+
```
|
|
949
|
+
Shows exactly what values are being used and why.
|
|
950
|
+
|
|
951
|
+
3. **Try explicit config path:**
|
|
952
|
+
```bash
|
|
953
|
+
mdcontext --config ./mdcontext.config.json index
|
|
954
|
+
```
|
|
955
|
+
|
|
956
|
+
---
|
|
957
|
+
|
|
958
|
+
## Examples
|
|
959
|
+
|
|
960
|
+
### Team Defaults
|
|
961
|
+
|
|
962
|
+
Share consistent settings across a team:
|
|
963
|
+
|
|
964
|
+
```typescript
|
|
965
|
+
// mdcontext.config.ts
|
|
966
|
+
import { defineConfig } from 'mdcontext'
|
|
967
|
+
|
|
968
|
+
export default defineConfig({
|
|
969
|
+
index: {
|
|
970
|
+
// Exclude team-specific directories
|
|
971
|
+
excludePatterns: [
|
|
972
|
+
'node_modules',
|
|
973
|
+
'.git',
|
|
974
|
+
'dist',
|
|
975
|
+
'build',
|
|
976
|
+
'.next',
|
|
977
|
+
'coverage',
|
|
978
|
+
],
|
|
979
|
+
},
|
|
980
|
+
search: {
|
|
981
|
+
// Team prefers more results
|
|
982
|
+
defaultLimit: 20,
|
|
983
|
+
minSimilarity: 0.6,
|
|
984
|
+
},
|
|
985
|
+
output: {
|
|
986
|
+
// Consistent formatting
|
|
987
|
+
prettyJson: true,
|
|
988
|
+
},
|
|
989
|
+
})
|
|
990
|
+
```
|
|
991
|
+
|
|
992
|
+
### CI/CD Pipeline
|
|
993
|
+
|
|
994
|
+
```yaml
|
|
995
|
+
# .github/workflows/docs.yml
|
|
996
|
+
jobs:
|
|
997
|
+
check-docs:
|
|
998
|
+
runs-on: ubuntu-latest
|
|
999
|
+
env:
|
|
1000
|
+
MDCONTEXT_OUTPUT_COLOR: 'false'
|
|
1001
|
+
MDCONTEXT_OUTPUT_FORMAT: 'json'
|
|
1002
|
+
steps:
|
|
1003
|
+
- uses: actions/checkout@v4
|
|
1004
|
+
- run: npm install -g mdcontext
|
|
1005
|
+
- run: mdcontext index ./docs
|
|
1006
|
+
- run: mdcontext stats --json > stats.json
|
|
1007
|
+
```
|
|
1008
|
+
|
|
1009
|
+
### Monorepo Setup
|
|
1010
|
+
|
|
1011
|
+
```typescript
|
|
1012
|
+
// packages/docs/mdcontext.config.ts
|
|
1013
|
+
import { defineConfig } from 'mdcontext'
|
|
1014
|
+
|
|
1015
|
+
export default defineConfig({
|
|
1016
|
+
paths: {
|
|
1017
|
+
root: './content',
|
|
1018
|
+
},
|
|
1019
|
+
index: {
|
|
1020
|
+
// Only this package's docs
|
|
1021
|
+
excludePatterns: ['node_modules'],
|
|
1022
|
+
maxDepth: 5,
|
|
1023
|
+
},
|
|
1024
|
+
})
|
|
1025
|
+
```
|
|
1026
|
+
|
|
1027
|
+
---
|
|
1028
|
+
|
|
1029
|
+
_For CLI command reference, see [USAGE.md](./019-USAGE.md)_
|
|
1030
|
+
|
|
1031
|
+
## Hybrid Search
|
|
1032
|
+
|
|
1033
|
+
mdcontext supports hybrid search combining BM25 keyword matching with semantic vector search for improved recall (15-30% improvement over single-method retrieval).
|
|
1034
|
+
|
|
1035
|
+
### How It Works
|
|
1036
|
+
|
|
1037
|
+
Hybrid mode uses Reciprocal Rank Fusion (RRF) to merge results from:
|
|
1038
|
+
- **BM25 keyword search**: Exact term matching (great for API names, error codes, identifiers)
|
|
1039
|
+
- **Semantic search**: Meaning-based matching (great for concepts and related terms)
|
|
1040
|
+
|
|
1041
|
+
### Usage
|
|
1042
|
+
|
|
1043
|
+
```bash
|
|
1044
|
+
# Auto-detect (uses hybrid if both indexes available)
|
|
1045
|
+
mdcontext search "authentication"
|
|
1046
|
+
|
|
1047
|
+
# Force hybrid mode
|
|
1048
|
+
mdcontext search --mode hybrid "authentication"
|
|
1049
|
+
|
|
1050
|
+
# Force keyword-only (BM25)
|
|
1051
|
+
mdcontext search --mode keyword "authentication"
|
|
1052
|
+
|
|
1053
|
+
# Force semantic-only
|
|
1054
|
+
mdcontext search --mode semantic "authentication"
|
|
1055
|
+
```
|
|
1056
|
+
|
|
1057
|
+
### Building Indexes
|
|
1058
|
+
|
|
1059
|
+
Both indexes are built automatically:
|
|
1060
|
+
|
|
1061
|
+
```bash
|
|
1062
|
+
# Build document index and BM25 index
|
|
1063
|
+
mdcontext index
|
|
1064
|
+
|
|
1065
|
+
# Build semantic embeddings (also updates BM25)
|
|
1066
|
+
mdcontext index --embed
|
|
1067
|
+
```
|
|
1068
|
+
|
|
1069
|
+
### Configuration
|
|
1070
|
+
|
|
1071
|
+
Default weights (no configuration needed):
|
|
1072
|
+
- BM25 weight: 1.0
|
|
1073
|
+
- Semantic weight: 1.0
|
|
1074
|
+
- RRF smoothing constant (k): 60
|
|
1075
|
+
|
|
1076
|
+
### When Hybrid is Used
|
|
1077
|
+
|
|
1078
|
+
- **--mode hybrid**: Always uses hybrid (fails if indexes missing)
|
|
1079
|
+
- **Auto-detect**: Uses hybrid when both BM25 and semantic indexes exist
|
|
1080
|
+
- **Fallback**: Degrades gracefully to semantic-only or keyword-only if one index is missing
|
|
1081
|
+
|
|
1082
|
+
## Pricing Data Maintenance
|
|
1083
|
+
|
|
1084
|
+
mdcontext uses hardcoded OpenAI pricing for embedding cost estimates. Prices change rarely for embedding models.
|
|
1085
|
+
|
|
1086
|
+
### Current Pricing
|
|
1087
|
+
|
|
1088
|
+
View current pricing data in `src/embeddings/openai-provider.ts`:
|
|
1089
|
+
|
|
1090
|
+
```typescript
|
|
1091
|
+
export const PRICING_DATA = {
|
|
1092
|
+
lastUpdated: '2024-09', // YYYY-MM format
|
|
1093
|
+
source: 'https://platform.openai.com/docs/pricing',
|
|
1094
|
+
prices: {
|
|
1095
|
+
'text-embedding-3-small': 0.02, // per 1M tokens
|
|
1096
|
+
'text-embedding-3-large': 0.13,
|
|
1097
|
+
'text-embedding-ada-002': 0.10,
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
```
|
|
1101
|
+
|
|
1102
|
+
### Staleness Warnings
|
|
1103
|
+
|
|
1104
|
+
Cost estimates show warning if pricing data is >90 days old:
|
|
1105
|
+
|
|
1106
|
+
```
|
|
1107
|
+
Estimated cost: ~$0.0200 (pricing as of 2024-09)
|
|
1108
|
+
⚠ Pricing data is 147 days old. May not reflect current rates.
|
|
1109
|
+
```
|
|
1110
|
+
|
|
1111
|
+
Warnings are non-blocking - operations proceed normally.
|
|
1112
|
+
|
|
1113
|
+
### Updating Pricing (Maintainers)
|
|
1114
|
+
|
|
1115
|
+
**Quarterly check process:**
|
|
1116
|
+
|
|
1117
|
+
1. Visit https://platform.openai.com/docs/pricing
|
|
1118
|
+
2. Update `PRICING_DATA.lastUpdated` to current YYYY-MM
|
|
1119
|
+
3. Update `PRICING_DATA.prices` if prices changed
|
|
1120
|
+
4. Commit: `git commit -m "chore: update OpenAI pricing data"`
|
|
1121
|
+
5. Release new version
|
|
1122
|
+
|
|
1123
|
+
**Why manual:** Embedding API pricing changes infrequently (checked quarterly is sufficient). No reliable free API exists for automated updates.
|