Commit 66570f9
authored
feat: add semantic chunker & centralize embeddings in rag-core-lib; helm + deps updates (#148)
Summary
- Adds an optional Semantic Chunker to the admin-api-lib and centralizes embedding implementations in rag-core-lib (rag-core-api now re-exports).
- Helm chart gains chunker selection + tuning; admin container now preloads NLTK data at startup.
- Dependency updates across admin libs/services; new tests for chunking logic.
Motivation
- Provide more accurate chunk boundaries (semantic-aware) while retaining the existing recursive splitter as the default.
- Deduplicate/embedder logic across projects to reduce drift and config duplication.
Key changes
- Admin chunking
- New `SemanticTextChunker` backed by LangChain’s `SemanticChunker`, with optional min/max enforcement via `RecursiveCharacterTextSplitter`.
- Trailing undersized chunks are sentence-aware rebalanced (NLTK Punkt with regex fallback) to avoid tiny tails.
- Configurable via:
- `CHUNKER_CLASS_TYPE_CHUNKER_TYPE`: `recursive` (default) or `semantic`
- `CHUNKER_MAX_SIZE` (default `1000`), `CHUNKER_OVERLAP` (default `100`)
- Semantic-only: `CHUNKER_BREAKPOINT_THRESHOLD_TYPE` (default `percentile`), `CHUNKER_BREAKPOINT_THRESHOLD_AMOUNT` (default `95`), `CHUNKER_BUFFER_SIZE` (default `1`), `CHUNKER_MIN_SIZE` (default `200`)
- DI wiring
- `DependencyContainer` selects chunker (`recursive` or `semantic`) and, for semantic mode, resolves embeddings via `EmbedderClassTypeSettings`:
- `stackit` → `StackitEmbedder` (with shared retry settings)
- `ollama` → `LangchainCommunityEmbedder(OllamaEmbeddings)`
- Container bootstrapping simplified in `main.py` (internalizes class-type wiring).
- Embeddings centralization
- New in `rag-core-lib`: `impl/embeddings/*` and embedder settings (`stackit`, `ollama`, `fake`), plus `EmbedderType` and base `Embedder`.
- `rag-core-api` re-exports these for backward compatibility (no breaking imports).
- Helm / deployment
- Values (`infrastructure/rag/values.yaml`): new `adminBackend.envs.chunker.*` keys for selection & tuning (chart default `recursive`; overlap default now `100`).
- Deployment: mounts NLTK data dir and fetches `punkt` + `averaged_perceptron_tagger_eng` at startup; adds `configmap.chunkerName` and `secret.stackitEmbedderName` to env sources.
- Behavior fixes & docs
- De-duplicate `meta["related"]` in page summaries.
- Docs: libs README adds “Chunker configuration (multiple chunkers)” and updates DI tables to rag-core-lib classes; admin-backend README adds “Chunking modes”.
- Tests
- New `semantic_text_chunker_test.py` exercising: supported-kwargs passthrough to LC chunker, empty-input behavior, min/max enforcement + balancing, sentence-aware split.
Configuration / migration
- Default remains `recursive` splitter; to enable semantic chunking:
1) Set `CHUNKER_CLASS_TYPE_CHUNKER_TYPE=semantic`.
2) Choose embeddings via `EMBEDDER_CLASS_TYPE_EMBEDDER_TYPE` (`stackit` or `ollama`) and configure:
- STACKIT: `STACKIT_EMBEDDER_MODEL`, `STACKIT_EMBEDDER_BASE_URL`, `STACKIT_EMBEDDER_API_KEY` (+ optional retry overrides).
- Ollama: `OLLAMA_EMBEDDER_MODEL`, `OLLAMA_EMBEDDER_BASE_URL`.
3) Ensure Helm chart has corresponding ConfigMaps/Secrets (`stackitEmbedder`, etc.).
- NLTK data is preloaded on container start; no runtime downloads required.
Dependencies
- Add: `langchain-experimental`, `nltk` (and transitive `joblib`).
- Bump: `fastapi` (0.118.x), `uvicorn` (0.37.x), `langfuse` (3.6.x), `langchain`/`community`/`core` minor versions, `requests` (2.32.5).
- Test note: ensure LC packages (`langchain_core`, etc.) are present to run unit tests locally.
Risks & mitigations
- Startup time increases slightly due to NLTK data fetch → mitigated via one-time download into an emptyDir.
- Semantic mode depends on external embeddings; ensure credentials/secrets are present before switching default.
- Chunk size tuning may affect vector DB costs; start with defaults and adjust based on retrieval quality.
Docs
- libs/README.md: “2.4 Chunker configuration (multiple chunkers)” and corrected DI references.
- services/admin-backend/README.md: “Chunking modes” and Helm guidance.1 parent 5ed9880 commit 66570f9
File tree
31 files changed
+1053
-420
lines changed- infrastructure/rag
- templates/admin-backend
- libs
- admin-api-lib
- src/admin_api_lib
- impl
- chunker
- information_enhancer
- settings
- tests
- rag-core-api/src/rag_core_api
- embeddings
- impl
- embeddings
- settings
- rag-core-lib/src/rag_core_lib/impl
- embeddings
- settings
- services/admin-backend
31 files changed
+1053
-420
lines changedLines changed: 13 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
| |||
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
38 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
39 | 45 | | |
40 | 46 | | |
41 | 47 | | |
| 48 | + | |
| 49 | + | |
42 | 50 | | |
43 | 51 | | |
44 | 52 | | |
| |||
108 | 116 | | |
109 | 117 | | |
110 | 118 | | |
| 119 | + | |
| 120 | + | |
111 | 121 | | |
112 | 122 | | |
113 | 123 | | |
| |||
116 | 126 | | |
117 | 127 | | |
118 | 128 | | |
| 129 | + | |
| 130 | + | |
119 | 131 | | |
120 | 132 | | |
121 | 133 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
338 | 338 | | |
339 | 339 | | |
340 | 340 | | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
341 | 344 | | |
342 | | - | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
343 | 351 | | |
344 | 352 | | |
345 | 353 | | |
| |||
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | | - | |
| 112 | + | |
| 113 | + | |
113 | 114 | | |
114 | 115 | | |
115 | | - | |
| 116 | + | |
116 | 117 | | |
117 | 118 | | |
118 | 119 | | |
Lines changed: 55 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
| 5 | + | |
11 | 6 | | |
| 7 | + | |
12 | 8 | | |
13 | 9 | | |
14 | 10 | | |
| |||
29 | 25 | | |
30 | 26 | | |
31 | 27 | | |
| 28 | + | |
32 | 29 | | |
33 | 30 | | |
34 | 31 | | |
| |||
41 | 38 | | |
42 | 39 | | |
43 | 40 | | |
| 41 | + | |
44 | 42 | | |
45 | 43 | | |
46 | 44 | | |
| |||
59 | 57 | | |
60 | 58 | | |
61 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
62 | 64 | | |
63 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
64 | 69 | | |
| 70 | + | |
65 | 71 | | |
66 | 72 | | |
67 | 73 | | |
| 74 | + | |
68 | 75 | | |
69 | 76 | | |
70 | 77 | | |
| |||
74 | 81 | | |
75 | 82 | | |
76 | 83 | | |
| 84 | + | |
77 | 85 | | |
78 | 86 | | |
79 | 87 | | |
80 | 88 | | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
81 | 92 | | |
82 | 93 | | |
83 | 94 | | |
| |||
88 | 99 | | |
89 | 100 | | |
90 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
91 | 106 | | |
92 | 107 | | |
93 | 108 | | |
| |||
96 | 111 | | |
97 | 112 | | |
98 | 113 | | |
99 | | - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
100 | 148 | | |
101 | 149 | | |
102 | 150 | | |
| |||
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
0 commit comments