Files
Enterprise-Knowledge-Base/LANGUAGE_REFACTORING_QUICK_REFERENCE.md
T
wizardchen e147209e77 feat: Implement comprehensive wiki feature for knowledge bases
This commit introduces the complete wiki feature for WeKnora, enabling AI-powered wiki page generation and management. The implementation includes:

**Backend Changes:**
- Wiki data model: WikiPage type with support for multiple page types (Summary, Entity, Concept, Index, Log)
- Database schema: wiki_pages table with full migration support
- WikiPageService: CRUD operations and page management
- WikiPageRepository: GORM-based persistence layer
- Wiki ingest pipeline: Automated generation of wiki pages from knowledge documents
  * Summary page generation using LLM
  * Entity and concept extraction in a single LLM call
  * Synthesis opportunity detection
  * Index page rebuilding
  * Log page maintenance
- Wiki boost feature: Enhance chat retrieval with wiki context
- Wiki linting: Maintenance and validation utilities
- Agent wiki tools: Enable agents to query and interact with wiki pages
- Wiki prompts: Comprehensive LLM prompt templates for all wiki generation tasks
- Language support: Reuse existing middleware language infrastructure for LLM prompts

**Frontend Changes:**
- Wiki browser UI: View all wiki pages with filtering and search
- Wiki API client: Knowledge base wiki management endpoints
- Knowledge base editor: Configure wiki settings (language, auto-ingest, synthesis model)
- i18n updates: Support for English, Korean, Russian, and Chinese interfaces

**Configuration:**
- Container DI: Wire up all wiki services
- Router: Register wiki API endpoints
- Task handling: Support async wiki ingest tasks

**Testing:**
- Unit tests for wiki page types
- Service layer tests
- Endpoint tests for wiki operations
- Integration tests with LLM mocking

**Documentation:**
- Language refactoring analysis and guides
- Implementation completion reports
- Quick reference guides for developers

**Key Features:**
✅ LLM-powered wiki page generation from documents
✅ Multi-language support (9+ languages)
✅ Automatic extraction of entities and concepts
✅ Synthesis opportunity detection
✅ Index and log page maintenance
✅ Progressive wiki building across multiple documents
✅ Agent-based wiki interaction
✅ Chat retrieval enhancement with wiki context
✅ Full frontend UI for wiki browsing

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-22 21:17:18 +08:00

112 lines
3.0 KiB
Markdown

# Language Middleware Refactoring - Quick Reference
## TL;DR
Replace 6 lines of hardcoded language logic in `wiki_ingest.go` with 1 line that reuses tested infrastructure.
## What to Change
**File:** `/internal/application/service/wiki_ingest.go`
**Lines:** 135-141
**Method:** `ProcessWikiIngest()`
### Simple Copy-Paste Replacement
```go
// OLD CODE (delete this):
// Determine language
lang := "the same language as the source document"
if kb.WikiConfig.WikiLanguage == "zh" {
lang = "Chinese (中文)"
} else if kb.WikiConfig.WikiLanguage == "en" {
lang = "English"
}
// NEW CODE (replace with this):
// Determine language
lang := types.LanguageLocaleName(kb.WikiConfig.WikiLanguage)
```
## Key Benefits
| Aspect | Before | After |
|--------|--------|-------|
| Languages Supported | 2 (zh, en) | 9+ (zh, en, ko, ja, ru, fr, de, es, pt) |
| Code Lines | 6 | 1 |
| Consistency | Varies | Unified middleware naming |
| Maintenance | Hardcoded | Centralized in `context_helpers.go` |
| Extension Cost | High | Low |
## No Breaking Changes
✅ Existing code works as-is
✅ No database migration needed
✅ No API changes
✅ Fully backward compatible
## Function Reference
**Function:** `types.LanguageLocaleName(locale string) string`
**Location:** `/internal/types/context_helpers.go` lines 85-112
**Already imported in wiki_ingest.go:** ✅ Yes (line 14)
**Supported Inputs:**
```
"zh-CN" or "zh" → "Chinese (Simplified)"
"zh-TW" or "zh-HK" → "Chinese (Traditional)"
"en-US" or "en" → "English"
"ko-KR" or "ko" → "Korean"
"ja-JP" or "ja" → "Japanese"
"ru-RU" or "ru" → "Russian"
"fr-FR" or "fr" → "French"
"de-DE" or "de" → "German"
"es-ES" or "es" → "Spanish"
"pt-BR" or "pt" → "Portuguese"
[any unknown] → returns the input as-is
```
## Testing
### Quick Test
```bash
cd /Users/wizard/code/go/src/git.woa.com/wxg-prc/WeKnora
go test -v ./internal/types
go test -v ./internal/application/service
```
### Manual Verification
```go
// In your test:
fmt.Println(types.LanguageLocaleName("zh")) // Should print: Chinese (Simplified)
fmt.Println(types.LanguageLocaleName("en")) // Should print: English
fmt.Println(types.LanguageLocaleName("ko")) // Should print: Korean
```
## Related Documentation
- Full analysis: `LANGUAGE_MIDDLEWARE_ANALYSIS.md`
- Implementation plan: `REFACTORING_PLAN.md`
- Main analysis: `AGENT_WIKI_ANALYSIS.md`
## Files Involved
| File | Purpose | Action |
|------|---------|--------|
| `/internal/middleware/language.go` | Language extraction middleware | Reference only |
| `/internal/types/context_helpers.go` | Language mapping functions | Reuse `LanguageLocaleName()` |
| `/internal/application/service/wiki_ingest.go` | Wiki ingest service | Update lines 135-141 |
## Implementation Checklist
- [ ] Open `wiki_ingest.go`
- [ ] Find lines 135-141
- [ ] Delete the 6-line language logic
- [ ] Replace with `lang := types.LanguageLocaleName(kb.WikiConfig.WikiLanguage)`
- [ ] Save file
- [ ] Run tests: `go test ./internal/...`
- [ ] Commit changes
That's it! 🎉