-
Notifications
You must be signed in to change notification settings - Fork 0
LLAMA_CPP_INTEGRATION
Status: Erforderlich für LLM Plugin Implementation
Datum: Dezember 2025
llama.cpp ist die primäre LLM-Engine für ThemisDB v1.3.0. Diese Dokumentation beschreibt die Integration.
Vorteile:
- Automatisches Dependency Management
- Konsistente Builds
- Einfache Integration in CMake
Status: llama.cpp ist NICHT standardmäßig in vcpkg verfügbar, aber wir können einen Custom Port erstellen.
Vorteile:
- Direkte Kontrolle über llama.cpp Version
- Einfache Updates
- Zugriff auf neueste Features
- Keine Commits im Repo (per .gitignore/.dockerignore ausgeschlossen)
Implementierung: Siehe unten
Vorteile:
- Shared Library für mehrere Projekte
- Weniger Build-Zeit
Nachteil:
- Versionskonflikte möglich
cd /path/to/ThemisDB
# Lokaler Clone (Root-Verzeichnis):
git clone https://github.com/ggerganov/llama.cpp.git llama.cpp
# Optional: auf spezifischen Tag wechseln
cd llama.cpp
git checkout b1696 # Beispiel: Stabiler Release Tag
cd ..
# Hinweis: ./llama.cpp ist per .gitignore/.dockerignore ausgeschlossen
# (wird nicht committed oder in Docker builds kopiert)# In ThemisDB/CMakeLists.txt
# LLM Support Option
option(THEMIS_ENABLE_LLM "Enable LLM plugin support (llama.cpp)" OFF)
if(THEMIS_ENABLE_LLM)
message(STATUS "LLM support enabled (llama.cpp)")
# llama.cpp Build Options
set(LLAMA_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(LLAMA_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(LLAMA_BUILD_SERVER OFF CACHE BOOL "" FORCE)
# GPU Support (optional)
if(THEMIS_ENABLE_CUDA)
set(LLAMA_CUDA ON CACHE BOOL "" FORCE)
set(LLAMA_CUDA_F16 ON CACHE BOOL "" FORCE)
endif()
if(THEMIS_ENABLE_METAL)
set(LLAMA_METAL ON CACHE BOOL "" FORCE)
endif()
if(THEMIS_ENABLE_VULKAN)
set(LLAMA_VULKAN ON CACHE BOOL "" FORCE)
endif()
# Add llama.cpp subdirectory (Root-Verzeichnis)
add_subdirectory(llama.cpp)
# Define LLM enabled
add_compile_definitions(THEMIS_LLM_ENABLED)
endif()# LLM Plugin Source Files
if(THEMIS_ENABLE_LLM)
set(LLM_PLUGIN_SOURCES
src/llm/llamacpp_plugin.cpp
src/llm/llm_plugin_manager.cpp
)
target_sources(themis_core PRIVATE ${LLM_PLUGIN_SOURCES})
# Link llama.cpp
target_link_libraries(themis_core PRIVATE
llama # llama.cpp library
)
target_include_directories(themis_core PRIVATE
${CMAKE_SOURCE_DIR}/llama.cpp/include
)
endif()cmake -B build -DTHEMIS_ENABLE_LLM=ONcmake -B build \
-DTHEMIS_ENABLE_LLM=ON \
-DTHEMIS_ENABLE_CUDA=ON \
-DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcccmake -B build \
-DTHEMIS_ENABLE_LLM=ON \
-DTHEMIS_ENABLE_METAL=ONcmake -B build \
-DTHEMIS_ENABLE_LLM=ON \
-DTHEMIS_ENABLE_VULKAN=ON#include "llama.h"
// Initialize llama backend
llama_backend_init();
// Model parameters
llama_model_params model_params = llama_model_default_params();
model_params.n_gpu_layers = 32; // GPU offload
model_params.use_mmap = true;
// Load model
llama_model* model = llama_load_model_from_file(
"/models/mistral-7b-q4.gguf",
model_params
);
// Context parameters
llama_context_params ctx_params = llama_context_default_params();
ctx_params.n_ctx = 4096;
ctx_params.n_batch = 512;
// Create context
llama_context* ctx = llama_new_context_with_model(model, ctx_params);// Tokenize prompt
std::vector<llama_token> tokens;
tokens.resize(4096);
int n_tokens = llama_tokenize(
model,
prompt.c_str(),
prompt.size(),
tokens.data(),
tokens.size(),
true, // add_bos
false // special
);
tokens.resize(n_tokens);
// Generate tokens
for (int i = 0; i < max_tokens; ++i) {
// Evaluate
llama_eval(ctx, tokens.data(), tokens.size(), 0);
// Sample next token
llama_token next_token = llama_sample_token(ctx, nullptr);
// Add to sequence
tokens.push_back(next_token);
// Check for EOS
if (next_token == llama_token_eos(model)) {
break;
}
}
// Decode tokens to text
std::string result = llama_token_to_str(ctx, tokens.data(), tokens.size());// Load LoRA adapter
llama_lora_adapter* adapter = llama_lora_adapter_load(
"/loras/legal-qa-v1.bin"
);
// Apply to context
llama_lora_adapter_set(ctx, adapter, 1.0f); // scale = 1.0
// Use for inference (same as above)
// Remove adapter
llama_lora_adapter_remove(ctx, adapter);
// Free adapter
llama_lora_adapter_free(adapter);// Free resources
llama_free(ctx);
llama_free_model(model);
llama_backend_free();ThemisDB v1.3.0
├─ themis_core (static/shared lib)
│ ├─ LLM Plugin Support (optional, THEMIS_ENABLE_LLM=ON)
│ │ └─ llama.cpp
│ │ ├─ ggml (included in llama.cpp)
│ │ └─ Optional GPU backends:
│ │ ├─ CUDA (NVIDIA)
│ │ ├─ Metal (Apple)
│ │ ├─ Vulkan (Cross-platform)
│ │ └─ hipBLAS (AMD ROCm)
│ └─ ... (other dependencies)
└─ themis_server (executable)
| Configuration | Binary Size | VRAM Usage | Build Time |
|---|---|---|---|
| CPU Only | +5 MB | 0 MB | +2 min |
| + CUDA | +15 MB | ~100 MB overhead | +5 min |
| + Metal | +8 MB | ~80 MB overhead | +3 min |
| + Vulkan | +12 MB | ~90 MB overhead | +4 min |
#include <gtest/gtest.h>
#include "llm/llamacpp_plugin.h"
TEST(LlamaIntegration, LoadModel) {
llama_backend_init();
LlamaCppPlugin plugin;
bool loaded = plugin.loadModel("/models/test-model.gguf");
EXPECT_TRUE(loaded);
EXPECT_TRUE(plugin.isModelLoaded());
llama_backend_free();
}TEST(LlamaIntegration, BasicInference) {
llama_backend_init();
LlamaCppPlugin plugin;
plugin.loadModel("/models/test-model.gguf");
InferenceRequest request;
request.prompt = "Hello, world!";
request.max_tokens = 10;
auto response = plugin.generate(request);
EXPECT_FALSE(response.text.empty());
EXPECT_GT(response.tokens_generated, 0);
llama_backend_free();
}Problem: llama.h not found
# Stelle sicher, dass der lokale Clone existiert (Projekt-Root)
ls -la ./llama.cpp
# Falls nicht vorhanden: lokalen Clone erstellen (nicht committen)
git clone https://github.com/ggerganov/llama.cpp.git llama.cppProblem: CUDA not found
# Setze CUDA_PATH
export CUDA_PATH=/usr/local/cuda
cmake -B build -DTHEMIS_ENABLE_CUDA=ONProblem: Model lädt nicht
- Prüfe GGUF Format (llama.cpp v2+)
- Prüfe Dateigröße und Permissions
- Prüfe VRAM Verfügbarkeit
Problem: Langsame Inferenz
- Erhöhe
n_gpu_layersfür mehr GPU Offload - Prüfe ob GPU wirklich genutzt wird (
nvidia-smi) - Reduziere
n_ctxwenn möglich
Für Windows (Visual Studio 2022, x64) steht ein robuster Build-Skript zur Verfügung, das die LLM-Integration aktiviert und die korrekten Generator-/Architektur-Flags setzt.
# LLM-Build und Link mit MSVC (Release)
powershell -File scripts/build-themis-server-llm.ps1
# Optional: Hilfe ausgeben
./build-msvc/bin/themis_server.exe --helpHinweise:
- Das Skript setzt
-G "Visual Studio 17 2022" -A x64und integriert vcpkg (CMAKE_TOOLCHAIN_FILE). - Zur Vermeidung von MSVC-spezifischen
char8_t-Fehlern wird demllama-Target der Compiler-Schalter/Zc:char8_t-hinzugefügt. -
llama.cpp/liegt als lokaler Clone im Projekt-Root und ist per.gitignoreund.dockerignoreausgeschlossen.
- llama.cpp Repository: https://github.com/ggerganov/llama.cpp
- GGUF Format: https://github.com/ggerganov/ggml/blob/master/docs/gguf.md
- Model Download: https://huggingface.co/models?library=gguf
- ThemisDB LLM Docs: LLM_PLUGIN_DEVELOPMENT_GUIDE.md
Status: Ready for Implementation
Version: ThemisDB v1.3.0
Last Updated: Dezember 2025
ThemisDB v1.3.4 | GitHub | Documentation | Discussions | License
Last synced: January 02, 2026 | Commit: 6add659
Version: 1.3.0 | Stand: Dezember 2025
- Übersicht
- Home
- Dokumentations-Index
- Quick Reference
- Sachstandsbericht 2025
- Features
- Roadmap
- Ecosystem Overview
- Strategische Übersicht
- Geo/Relational Storage
- RocksDB Storage
- MVCC Design
- Transaktionen
- Time-Series
- Memory Tuning
- Chain of Thought Storage
- Query Engine & AQL
- AQL Syntax
- Explain & Profile
- Rekursive Pfadabfragen
- Temporale Graphen
- Zeitbereichs-Abfragen
- Semantischer Cache
- Hybrid Queries (Phase 1.5)
- AQL Hybrid Queries
- Hybrid Queries README
- Hybrid Query Benchmarks
- Subquery Quick Reference
- Subquery Implementation
- Content Pipeline
- Architektur-Details
- Ingestion
- JSON Ingestion Spec
- Enterprise Ingestion Interface
- Geo-Processor Design
- Image-Processor Design
- Hybrid Search Design
- Fulltext API
- Hybrid Fusion API
- Stemming
- Performance Tuning
- Migration Guide
- Future Work
- Pagination Benchmarks
- Enterprise README
- Scalability Features
- HTTP Client Pool
- Build Guide
- Implementation Status
- Final Report
- Integration Analysis
- Enterprise Strategy
- Verschlüsselungsstrategie
- Verschlüsselungsdeployment
- Spaltenverschlüsselung
- Encryption Next Steps
- Multi-Party Encryption
- Key Rotation Strategy
- Security Encryption Gap Analysis
- Audit Logging
- Audit & Retention
- Compliance Audit
- Compliance
- Extended Compliance Features
- Governance-Strategie
- Compliance-Integration
- Governance Usage
- Security/Compliance Review
- Threat Model
- Security Hardening Guide
- Security Audit Checklist
- Security Audit Report
- Security Implementation
- Development README
- Code Quality Pipeline
- Developers Guide
- Cost Models
- Todo Liste
- Tool Todo
- Core Feature Todo
- Priorities
- Implementation Status
- Roadmap
- Future Work
- Next Steps Analysis
- AQL LET Implementation
- Development Audit
- Sprint Summary (2025-11-17)
- WAL Archiving
- Search Gap Analysis
- Source Documentation Plan
- Changefeed README
- Changefeed CMake Patch
- Changefeed OpenAPI
- Changefeed OpenAPI Auth
- Changefeed SSE Examples
- Changefeed Test Harness
- Changefeed Tests
- Dokumentations-Inventar
- Documentation Summary
- Documentation TODO
- Documentation Gap Analysis
- Documentation Consolidation
- Documentation Final Status
- Documentation Phase 3
- Documentation Cleanup Validation
- API
- Authentication
- Cache
- CDC
- Content
- Geo
- Governance
- Index
- LLM
- Query
- Security
- Server
- Storage
- Time Series
- Transaction
- Utils
Vollständige Dokumentation: https://makr-code.github.io/ThemisDB/