π§ CrumbVector - Certified Code in Vector Space
Semantic Code Search mit Trust Layer
π― Die Idee
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β
β CERTIFIED REPO β CHUNKING β EMBEDDING β VECTOR DB β SEMANTIC β
β β
β βββββββββββ βββββββββ βββββββββ βββββββββ ββββββββββ β
β β .git β β Code β β float β βChromaDBβ β "Wie β β
β β CKL β βββΊ β Chunksβ βββΊ β [384] β βββΊ βQdrant β ββββ mache β β
β β β Trustβ β +Meta β β Vectorβ βPineconeβ β OneDropβ β
β βββββββββββ βββββββββ βββββββββ βββββββββ ββββββββββ β
β β
β Nur TRUSTED Code wird vektorisiert! β
β Query β Semantische Suche β Verified Code Snippets β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π Trust Layer
Was macht ein Repo "zertifiziert"?
# .crumbvector/trust.yaml
certification:
status: verified
license: CKL-1.0 # oder MIT, Apache, etc.
verified_by: crumbforest
verified_at: 2026-01-13
trust_level: 3 # 1-5 scale
# 1 = unknown
# 2 = community reviewed
# 3 = maintainer verified
# 4 = foundation certified
# 5 = core/official
allowed_for:
- teaching
- code_completion
- pattern_search
- remix
excluded_patterns:
- "**/*.env"
- "**/secrets/**"
- "**/node_modules/**"
π Der Pipeline Flow
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β
β 1. INGEST β
β βββ Git Clone (certified repo) β
β βββ Verify Trust (.crumbvector/trust.yaml) β
β βββ Check License (CKL, MIT, Apache...) β
β βββ Extract Metadata (author, date, tags) β
β β
β 2. CHUNK β
β βββ Split by: function, class, file, pattern β
β βββ Keep context: imports, comments, docstrings β
β βββ Attach metadata: file, line, repo, license β
β βββ Smart boundaries: AST-aware splitting β
β β
β 3. EMBED β
β βββ Code-optimized model (CodeBERT, StarCoder, etc.) β
β βββ Or: Local model (Ollama + nomic-embed-text) β
β βββ Generate vectors: [384] or [768] dimensions β
β βββ Batch processing for efficiency β
β β
β 4. STORE β
β βββ Vector DB: ChromaDB (local), Qdrant, Pinecone β
β βββ Metadata: license, trust_level, source, language β
β βββ Collections: by repo, by language, by topic β
β βββ Index: for fast similarity search β
β β
β 5. QUERY β
β βββ Natural language: "Wie mache ich einen One Drop Beat?" β
β βββ Code snippet: "sound('bd').delay()" β
β βββ Filter: trust_level >= 3, license = CKL β
β βββ Return: relevant chunks + metadata + source link β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π Architektur
crumbvector/
βββ ingest/
β βββ git_loader.py # Clone & verify repos
β βββ trust_checker.py # Validate certification
β βββ license_parser.py # Extract license info
β
βββ chunk/
β βββ code_chunker.py # AST-aware splitting
β βββ pattern_chunker.py # For Strudel patterns
β βββ doc_chunker.py # Markdown/comments
β
βββ embed/
β βββ local_embedder.py # Ollama integration
β βββ openai_embedder.py # OpenAI embeddings
β βββ code_embedder.py # CodeBERT/StarCoder
β
βββ store/
β βββ chroma_store.py # ChromaDB (local, free)
β βββ qdrant_store.py # Qdrant (local/cloud)
β βββ collections.py # Collection management
β
βββ query/
β βββ semantic_search.py # Natural language queries
β βββ code_search.py # Code similarity
β βββ filter_engine.py # Trust/license filtering
β
βββ api/
β βββ server.py # FastAPI server
β βββ cli.py # Command line interface
β
βββ config/
βββ trusted_repos.yaml # List of certified repos
βββ settings.yaml # Configuration
π οΈ Implementation
1. Git Loader mit Trust Check
#!/usr/bin/env python3
"""
CrumbVector - Git Loader with Trust Verification
"""
import os
import yaml
import subprocess
from pathlib import Path
from dataclasses import dataclass
from typing import Optional, List
@dataclass
class TrustInfo:
status: str
license: str
trust_level: int
verified_by: str
allowed_for: List[str]
@dataclass
class CertifiedRepo:
url: str
local_path: Path
trust: TrustInfo
def clone_repo(url: str, target_dir: Path) -> Path:
"""Clone a git repository."""
repo_name = url.split('/')[-1].replace('.git', '')
local_path = target_dir / repo_name
if local_path.exists():
# Pull latest
subprocess.run(['git', '-C', str(local_path), 'pull'], check=True)
else:
# Clone
subprocess.run(['git', 'clone', url, str(local_path)], check=True)
return local_path
def verify_trust(repo_path: Path) -> Optional[TrustInfo]:
"""Check if repo has valid trust certification."""
trust_file = repo_path / '.crumbvector' / 'trust.yaml'
# Also check for CKL license
ckl_file = repo_path / 'LICENSE.CKL'
license_file = repo_path / 'LICENSE'
if trust_file.exists():
with open(trust_file) as f:
data = yaml.safe_load(f)
cert = data.get('certification', {})
return TrustInfo(
status=cert.get('status', 'unknown'),
license=cert.get('license', 'unknown'),
trust_level=data.get('trust_level', 1),
verified_by=cert.get('verified_by', 'unknown'),
allowed_for=data.get('allowed_for', [])
)
# Fallback: Check for known licenses
if ckl_file.exists():
return TrustInfo(
status='license_only',
license='CKL-1.0',
trust_level=2,
verified_by='auto',
allowed_for=['teaching', 'remix']
)
return None
def load_certified_repo(url: str, target_dir: Path,
min_trust_level: int = 2) -> Optional[CertifiedRepo]:
"""Load and verify a repository."""
local_path = clone_repo(url, target_dir)
trust = verify_trust(local_path)
if trust is None:
print(f"β οΈ No trust info found for {url}")
return None
if trust.trust_level < min_trust_level:
print(f"β οΈ Trust level {trust.trust_level} below minimum {min_trust_level}")
return None
if trust.status not in ['verified', 'license_only']:
print(f"β οΈ Status '{trust.status}' not acceptable")
return None
print(f"β
Loaded {url} (trust: {trust.trust_level}, license: {trust.license})")
return CertifiedRepo(url=url, local_path=local_path, trust=trust)
2. Code Chunker (AST-aware)
"""
CrumbVector - Smart Code Chunker
"""
import ast
from pathlib import Path
from dataclasses import dataclass
from typing import List, Optional
import re
@dataclass
class CodeChunk:
content: str
language: str
file_path: str
start_line: int
end_line: int
chunk_type: str # function, class, pattern, comment
metadata: dict
def chunk_python(file_path: Path, repo_info: dict) -> List[CodeChunk]:
"""Chunk Python file using AST."""
chunks = []
content = file_path.read_text()
try:
tree = ast.parse(content)
except SyntaxError:
# Fallback to line-based chunking
return chunk_by_lines(file_path, content, 'python', repo_info)
for node in ast.walk(tree):
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
chunk = extract_node_chunk(content, node, 'function', file_path, repo_info)
chunks.append(chunk)
elif isinstance(node, ast.ClassDef):
chunk = extract_node_chunk(content, node, 'class', file_path, repo_info)
chunks.append(chunk)
return chunks
def chunk_javascript(file_path: Path, repo_info: dict) -> List[CodeChunk]:
"""Chunk JavaScript/Strudel patterns."""
chunks = []
content = file_path.read_text()
lines = content.split('\n')
# Pattern: let name = ...
pattern_regex = r'^(let|const|var)\s+(\w+)\s*='
current_chunk = []
current_start = 0
current_name = None
for i, line in enumerate(lines):
match = re.match(pattern_regex, line)
if match and current_chunk:
# Save previous chunk
chunks.append(CodeChunk(
content='\n'.join(current_chunk),
language='javascript',
file_path=str(file_path),
start_line=current_start,
end_line=i - 1,
chunk_type='pattern',
metadata={**repo_info, 'name': current_name}
))
current_chunk = []
current_start = i
current_name = match.group(2)
current_chunk.append(line)
if match and current_name is None:
current_name = match.group(2)
current_start = i
# Don't forget last chunk
if current_chunk:
chunks.append(CodeChunk(
content='\n'.join(current_chunk),
language='javascript',
file_path=str(file_path),
start_line=current_start,
end_line=len(lines) - 1,
chunk_type='pattern',
metadata={**repo_info, 'name': current_name}
))
return chunks
def chunk_strudel_pattern(file_path: Path, repo_info: dict) -> List[CodeChunk]:
"""Special chunker for Strudel .js patterns."""
chunks = []
content = file_path.read_text()
# Split by section comments
sections = re.split(r'// [ββ]{10,}', content)
for i, section in enumerate(sections):
if section.strip():
# Extract section title if present
title_match = re.search(r'// ([A-Z][A-Z\s]+)', section)
title = title_match.group(1).strip() if title_match else f"Section {i}"
chunks.append(CodeChunk(
content=section.strip(),
language='strudel',
file_path=str(file_path),
start_line=0, # Would need proper line tracking
end_line=0,
chunk_type='section',
metadata={**repo_info, 'section': title}
))
return chunks
3. Embedder (Local with Ollama)
"""
CrumbVector - Local Embedding with Ollama
"""
import requests
import numpy as np
from typing import List
from dataclasses import dataclass
@dataclass
class EmbeddedChunk:
chunk: 'CodeChunk'
vector: np.ndarray
model: str
class OllamaEmbedder:
"""Generate embeddings using local Ollama."""
def __init__(self,
model: str = "nomic-embed-text",
base_url: str = "http://localhost:11434"):
self.model = model
self.base_url = base_url
def embed_text(self, text: str) -> np.ndarray:
"""Generate embedding for single text."""
response = requests.post(
f"{self.base_url}/api/embeddings",
json={
"model": self.model,
"prompt": text
}
)
response.raise_for_status()
return np.array(response.json()['embedding'])
def embed_chunks(self, chunks: List['CodeChunk']) -> List[EmbeddedChunk]:
"""Generate embeddings for multiple chunks."""
embedded = []
for chunk in chunks:
# Prepare text with context
text = self._prepare_chunk_text(chunk)
vector = self.embed_text(text)
embedded.append(EmbeddedChunk(
chunk=chunk,
vector=vector,
model=self.model
))
return embedded
def _prepare_chunk_text(self, chunk: 'CodeChunk') -> str:
"""Prepare chunk text for embedding with metadata context."""
meta = chunk.metadata
# Add context for better semantic matching
context_parts = [
f"Language: {chunk.language}",
f"Type: {chunk.chunk_type}",
]
if 'name' in meta:
context_parts.append(f"Name: {meta['name']}")
if 'section' in meta:
context_parts.append(f"Section: {meta['section']}")
if 'genre' in meta:
context_parts.append(f"Genre: {meta['genre']}")
context = " | ".join(context_parts)
return f"{context}\n\n{chunk.content}"
4. ChromaDB Store
"""
CrumbVector - ChromaDB Storage
"""
import chromadb
from chromadb.config import Settings
from typing import List, Optional, Dict
import json
class CrumbVectorStore:
"""Store and query code vectors with ChromaDB."""
def __init__(self, persist_dir: str = "./crumbvector_db"):
self.client = chromadb.Client(Settings(
chroma_db_impl="duckdb+parquet",
persist_directory=persist_dir,
anonymized_telemetry=False
))
# Main collection for code
self.code_collection = self.client.get_or_create_collection(
name="certified_code",
metadata={"description": "Certified code from trusted repos"}
)
# Separate collection for Strudel patterns
self.pattern_collection = self.client.get_or_create_collection(
name="strudel_patterns",
metadata={"description": "Music patterns for Strudel"}
)
def add_chunks(self, embedded_chunks: List['EmbeddedChunk'],
collection: str = "code"):
"""Add embedded chunks to the store."""
coll = (self.pattern_collection if collection == "patterns"
else self.code_collection)
ids = []
embeddings = []
documents = []
metadatas = []
for i, ec in enumerate(embedded_chunks):
chunk_id = f"{ec.chunk.file_path}:{ec.chunk.start_line}:{i}"
ids.append(chunk_id)
embeddings.append(ec.vector.tolist())
documents.append(ec.chunk.content)
metadatas.append({
"language": ec.chunk.language,
"chunk_type": ec.chunk.chunk_type,
"file_path": ec.chunk.file_path,
"start_line": ec.chunk.start_line,
"end_line": ec.chunk.end_line,
"model": ec.model,
**{k: str(v) for k, v in ec.chunk.metadata.items()}
})
coll.add(
ids=ids,
embeddings=embeddings,
documents=documents,
metadatas=metadatas
)
def query(self,
query_text: str,
query_embedding: List[float],
n_results: int = 5,
collection: str = "code",
filters: Optional[Dict] = None) -> List[Dict]:
"""Query for similar code chunks."""
coll = (self.pattern_collection if collection == "patterns"
else self.code_collection)
where_filter = None
if filters:
where_filter = {"$and": [
{k: {"$eq": v}} for k, v in filters.items()
]}
results = coll.query(
query_embeddings=[query_embedding],
n_results=n_results,
where=where_filter,
include=["documents", "metadatas", "distances"]
)
# Format results
formatted = []
for i in range(len(results['ids'][0])):
formatted.append({
"id": results['ids'][0][i],
"content": results['documents'][0][i],
"metadata": results['metadatas'][0][i],
"distance": results['distances'][0][i],
"query": query_text
})
return formatted
def persist(self):
"""Persist the database to disk."""
self.client.persist()
5. Query API
"""
CrumbVector - Query API
"""
from fastapi import FastAPI, Query
from pydantic import BaseModel
from typing import List, Optional
import uvicorn
app = FastAPI(title="CrumbVector API", version="0.1.0")
# Initialize components
embedder = OllamaEmbedder()
store = CrumbVectorStore()
class SearchQuery(BaseModel):
query: str
n_results: int = 5
collection: str = "patterns"
language: Optional[str] = None
min_trust_level: Optional[int] = None
genre: Optional[str] = None
class SearchResult(BaseModel):
content: str
file_path: str
language: str
distance: float
metadata: dict
@app.post("/search", response_model=List[SearchResult])
async def search_code(search: SearchQuery):
"""Semantic search for code snippets."""
# Generate query embedding
query_vector = embedder.embed_text(search.query)
# Build filters
filters = {}
if search.language:
filters["language"] = search.language
if search.min_trust_level:
filters["trust_level"] = {"$gte": search.min_trust_level}
if search.genre:
filters["genre"] = search.genre
# Query
results = store.query(
query_text=search.query,
query_embedding=query_vector.tolist(),
n_results=search.n_results,
collection=search.collection,
filters=filters if filters else None
)
return [SearchResult(
content=r["content"],
file_path=r["metadata"]["file_path"],
language=r["metadata"]["language"],
distance=r["distance"],
metadata=r["metadata"]
) for r in results]
@app.get("/health")
async def health():
return {"status": "ok", "service": "crumbvector"}
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8765)
π΅ Use Case: Strudel Pattern Search
# Query
curl -X POST http://localhost:8765/search \
-H "Content-Type: application/json" \
-d '{
"query": "Wie mache ich einen One Drop Beat?",
"collection": "patterns",
"genre": "reggae",
"n_results": 3
}'
# Response
[
{
"content": "let oneDrop = stack(\n sound(\"~ ~ bd ~\").gain(1.1).lpf(150),\n sound(\"~ ~ rim ~\").gain(0.7).hpf(800)\n)",
"file_path": "crumbmidi/patterns/REGGAE_DUB_75BPM.js",
"language": "strudel",
"distance": 0.23,
"metadata": {
"genre": "reggae",
"section": "ONE DROP",
"trust_level": "3",
"license": "CKL-1.0"
}
},
...
]
π Trust Levels fΓΌr CrumbMidi
# crumbmidi/.crumbvector/trust.yaml
certification:
status: verified
license: CKL-1.0
verified_by: crumbforest
verified_at: 2026-01-13
trust_level: 4 # Foundation certified
allowed_for:
- teaching
- code_completion
- pattern_search
- remix
- ai_training # Explicit opt-in!
genres:
- gfunk
- dnb
- house
- baobab
- reggae
languages:
- javascript
- strudel
- bash
π¦ FunkFox Vision
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β
β "Wie mache ich Drums wie Armand Van Helden?" β
β β β
β βΌ β
β βββββββββββββββββ β
β β CrumbVector β β
β β Query API β β
β βββββββββββββββββ β
β β β
β ββββββββββββββββββββΌβββββββββββββββββββ β
β βΌ βΌ βΌ β
β ββββββββββββββββββ ββββββββββββββββββ ββββββββββββββββββ β
β β HOUSE Pattern β β Filter House β β Four on Floor β β
β β from CrumbMidi β β Tutorial β β Example β β
β β β CKL License β β β Trust: 4 β β β Verified β β
β ββββββββββββββββββ ββββββββββββββββββ ββββββββββββββββββ β
β β
β Nur TRUSTED Code β’ Nur LICENSED Content β’ Keine Halluzination β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π NΓ€chste Schritte
- [ ] ChromaDB Setup - Lokale Vector DB
- [ ] Ollama Embeddings - nomic-embed-text oder mxbai-embed-large
- [ ] Trust YAML - FΓΌr alle CrumbMidi Patterns
- [ ] Ingest Pipeline - Git β Chunk β Embed β Store
- [ ] Query API - FastAPI Server
- [ ] CLI Tool -
crumbvector search "one drop beat" - [ ] Integration - Mit Strudel / Terminal Dojo
π§ CRUMBVECTOR π§
Code verstehen.
Code finden.
Code vertrauen.
Semantic Search fΓΌr Certified Code.
#crumbvector #rag #vectordb #chromadb #embeddings #trust
π§ ππ