-
Notifications
You must be signed in to change notification settings - Fork 2
Technical Architecture
github-actions[bot] edited this page Oct 30, 2025
·
7 revisions
Deep dive into Sylphx Flow's technical implementation, focusing on Starcode embeddings, functional architecture, and MCP integration.
Starcode is a state-of-the-art code embedding model that transforms code into semantic vectors for understanding and search.
Key Properties:
- π 70+ Programming Languages - From TypeScript to Assembly
- π£οΈ Natural Language Support - English, Chinese, Japanese, etc.
- π― Semantic Understanding - Understands what code does, not just what it says
- β‘ High Performance - Fast embedding generation
- π¨ Context-Aware - Understands code structure and relationships
| Feature | Starcode | OpenAI Embeddings | CodeBERT | UnixCoder |
|---|---|---|---|---|
| Languages | 70+ | Limited | ~10 | ~5 |
| NL + Code | β Hybrid | Separate | β Hybrid | Limited |
| Code Structure | β Deep | Surface | β Deep | Medium |
| Performance | Fast | API latency | Fast | Medium |
| Cost | Open source | Per token | Open source | Open source |
| Context Size | 2048 | 8192 | 512 | 512 |
Why Sylphx Flow chose Starcode:
- 70+ language support - True polyglot search
- Hybrid NL+Code - Search in any language, find any code
- Open source - No API costs, runs locally
- Optimized for code - Better than general-purpose embeddings
Sylphx Flow is the first production system to implement:
- Starcode at scale - Indexing entire codebases
- Hybrid search - Natural language + code simultaneously
- Real-time indexing - Fast reindexing for code changes
- Cross-language understanding - Search concepts across languages
// Starcode embedding pipeline
class StarcodeEmbeddings {
async embed(code: string): Promise<number[]> {
// 1. Tokenization (code-aware)
const tokens = this.tokenize(code);
// 2. Generate embeddings (1536 dimensions)
const embedding = await this.model.encode(tokens);
// 3. Normalize for similarity search
return this.normalize(embedding);
}
private tokenize(code: string): Token[] {
// Code-aware tokenization
// Understands: functions, classes, variables, comments
// Preserves: structure, syntax, semantic meaning
}
}// Semantic similarity search
class VectorSearch {
async search(query: string, limit: number = 10) {
// 1. Embed the query
const queryVector = await this.embeddings.embed(query);
// 2. Cosine similarity search in vector database
const results = await this.vectorDB.similaritySearch(
queryVector,
limit,
threshold: 0.7 // Minimum similarity score
);
// 3. Rank by relevance
return this.rankResults(results);
}
}// Smart code chunking
class CodeChunker {
chunk(code: string): Chunk[] {
// Parse code into semantic units
const ast = this.parse(code);
// Chunk by:
// - Function definitions
// - Class definitions
// - Import statements
// - Comment blocks
// - Logical sections
return this.ast.extractSemanticUnits();
}
}Tier 1 (Full Support):
TypeScript, JavaScript, Python, Java, C++, C#, Go, Rust,
Ruby, PHP, Swift, Kotlin, Scala, Dart, R
Tier 2 (Strong Support):
Haskell, OCaml, Erlang, Elixir, Clojure, F#, Julia, Lua,
Perl, Shell, PowerShell, Groovy, Objective-C
Tier 3 (Basic Support):
Assembly, COBOL, Fortran, Ada, Lisp, Scheme, Prolog,
SQL, HTML, CSS, YAML, JSON, XML, Markdown, ...
Plus 40+ more languages!
// Example: Search for authentication across languages
// Query in ANY natural language
flow codebase search "user authentication logic" // English
flow codebase search "η¨ζΆθͺθιθΌ―" // Chinese
flow codebase search "γ¦γΌγΆγΌθͺθ¨ΌγγΈγγ―" // Japanese
// All find the same code in multiple programming languages:
// TypeScript
function authenticateUser(credentials: Credentials) {
// ...
}
// Python
def authenticate_user(credentials):
# ...
// Go
func AuthenticateUser(creds Credentials) error {
// ...
}
// Java
public User authenticateUser(Credentials credentials) {
// ...
}
// All matched semantically, not by keywords!// Hybrid search architecture
class HybridSearch {
async search(query: string) {
// 1. Determine query type
const type = this.analyzeQuery(query);
if (type === 'natural_language') {
// Search using NL understanding
return this.searchByMeaning(query);
} else if (type === 'code_pattern') {
// Search using code structure
return this.searchByStructure(query);
} else {
// Hybrid: combine both approaches
const nlResults = await this.searchByMeaning(query);
const codeResults = await this.searchByStructure(query);
return this.mergeResults(nlResults, codeResults);
}
}
}// Natural language queries in different languages
"code that handles user login" // English
"θηη¨ζΆη»ε
₯η代璼" // Chinese
"γ¦γΌγΆγΌγγ°γ€γ³γε¦ηγγγ³γΌγ" // Japanese
"cΓ³digo que maneja el login" // Spanish
// All find the same authentication code!
// Code pattern queries
"async function authenticate"
"class AuthService extends"
"def authenticate_user"
// Technical concept queries
"JWT token generation"
"password hashing with bcrypt"
"OAuth 2.0 flow implementation"
// All work seamlessly with Starcode!Sylphx Flow is built on pure functional programming principles for several key reasons:
// MCP tools = Pure functions
// Easy to compose
// Sequential composition
const result = await pipe(
knowledge_search,
codebase_search,
synthesize
)("authentication");
// Parallel composition
const [knowledge, code, time] = await Promise.all([
knowledge_search("auth"),
codebase_search("auth"),
time_get_current()
]);
// Conditional composition
const result = query.includes("security")
? await compose(knowledge_search, security_check)
: await knowledge_search(query);// Pure function = Same input β Same output
test('knowledge_search is pure', () => {
const result1 = knowledge_search('react');
const result2 = knowledge_search('react');
expect(result1).toEqual(result2);
// No mocks needed!
});
// Easy to test edge cases
test('handles empty results', () => {
const result = knowledge_search('nonexistent');
expect(result).toEqual([]);
});// No shared state = Safe parallelization
async function handleComplexQuery(query: string) {
// All execute in parallel
const results = await Promise.all([
knowledge_search(query),
codebase_search(query),
time_get_current(),
sysinfo_get()
]);
// No race conditions, no locks needed
return synthesize(results);
}// Agents as pure functions
type Agent = (task: Task, context: Context) => Result;
// Orchestrator composes agents
class Orchestrator {
async execute(task: Task) {
const context = await this.buildContext();
// Compose agents functionally
return await pipe(
(t) => this.coderAgent(t, context),
(r) => this.reviewerAgent(r, context),
(r) => this.writerAgent(r, context)
)(task);
}
}// β Bad: Inheritance hierarchy
class BaseSearch {
search() { }
}
class KnowledgeSearch extends BaseSearch {
search() { /* override */ }
}
class CodebaseSearch extends BaseSearch {
search() { /* override */ }
}
// β
Good: Function composition
const createSearch = (embedFn, dbFn) => async (query) => {
const embedding = await embedFn(query);
return await dbFn(embedding);
};
const knowledgeSearch = createSearch(
embedKnowledge,
searchKnowledgeDB
);
const codebaseSearch = createSearch(
embedCode,
searchCodebaseDB
);// β
Pure: No side effects
function knowledge_search(query: string): Promise<Result[]> {
// Only depends on input
// Always returns same result for same input
// No mutations, no external state
}
// β Impure: Has side effects
let cache = {};
function impure_search(query: string) {
if (cache[query]) return cache[query];
const result = search(query);
cache[query] = result; // Side effect!
return result;
}// β
Immutable transformations
const addResult = (results: Result[], newResult: Result) => [
...results,
newResult
];
const filterResults = (results: Result[], predicate) =>
results.filter(predicate);
// β Mutable operations
const addResult = (results, newResult) => {
results.push(newResult); // Mutation!
return results;
};// β
Declarative: What, not how
const results = await pipe(
knowledge_search,
filter(relevantOnly),
map(formatResult),
take(5)
)("authentication");
// β Imperative: How, step by step
const results = [];
const searchResults = await knowledge_search("authentication");
for (let i = 0; i < searchResults.length; i++) {
if (isRelevant(searchResults[i])) {
results.push(formatResult(searchResults[i]));
if (results.length >= 5) break;
}
}// Data flows through transformations
const processQuery = pipe(
normalize,
tokenize,
embed,
search,
rank,
format
);
const result = await processQuery(userQuery);// Compose small functions into larger ones
const searchWithContext = compose(
synthesize,
parallel([
knowledge_search,
codebase_search,
getSystemContext
])
);// Functions that operate on functions
const withCache = (fn) => {
const cache = new Map();
return async (input) => {
if (cache.has(input)) return cache.get(input);
const result = await fn(input);
cache.set(input, result);
return result;
};
};
const cachedSearch = withCache(knowledge_search);// Result type for explicit error handling
type Result<T, E> = Ok<T> | Err<E>;
const search = async (query: string): Promise<Result<Data[], Error>> => {
try {
const data = await performSearch(query);
return Ok(data);
} catch (error) {
return Err(error);
}
};
// Chain operations safely
const result = await search("query")
.then(map(formatResult))
.then(filter(relevantOnly));// Modular plugin architecture
class MCPServer {
plugins: Plugin[] = [
new KnowledgePlugin(),
new CodebasePlugin(),
new TimePlugin()
];
async handleRequest(request: MCPRequest) {
// Route to appropriate plugin
const plugin = this.findPlugin(request.tool);
return await plugin.execute(request);
}
}// Each domain = one plugin
interface Plugin {
name: string;
tools: Tool[];
initialize(): Promise<void>;
shutdown(): Promise<void>;
}
class KnowledgePlugin implements Plugin {
name = "knowledge";
tools = [
{
name: "knowledge_search",
description: "Search curated guidelines",
inputSchema: knowledgeSearchSchema,
handler: this.search.bind(this)
},
{
name: "knowledge_get",
description: "Get specific document",
inputSchema: knowledgeGetSchema,
handler: this.get.bind(this)
}
];
async search(params: SearchParams) {
// Pure function implementation
return await this.storage.search(params.query);
}
}// Unified storage interface
interface UnifiedStorage {
search(query: string): Promise<Result[]>;
get(key: string): Promise<Data | null>;
set(key: string, data: Data): Promise<void>;
delete(key: string): Promise<void>;
}
// Implementations for different domains
class KnowledgeStorage implements UnifiedStorage {
// Uses Starcode embeddings
// Stores in vector database
}
class CodebaseStorage implements UnifiedStorage {
// Uses Starcode embeddings
// Stores in vector database
// Monitors file changes
}// Starcode embedding generation
const performance = {
singleFile: "10-50ms", // Average TypeScript file
largeFile: "50-200ms", // 1000+ lines
batchProcessing: "100-500ms", // 10 files
fullIndex: "1-5 minutes" // 1000 files
};// Vector similarity search
const searchPerformance = {
coldSearch: "100-300ms", // First search
warmSearch: "20-50ms", // Subsequent searches
complexQuery: "50-100ms", // Multi-term queries
largDatabase: "100-200ms" // 10,000+ entries
};// Performance at scale
const scalability = {
files: {
small: "< 100 files: <1s",
medium: "100-1,000 files: 1-5s",
large: "1,000-10,000 files: 10-60s",
xlarge: "10,000+ files: 1-5 min"
},
memory: {
small: "~50MB",
medium: "~200MB",
large: "~500MB",
xlarge: "~1-2GB"
}
};Chose Starcode:
- β 70+ languages vs limited
- β Code-optimized vs general-purpose
- β Local/free vs API/cost
- β Fast vs latency
- β 1536 dims vs 3072 dims (less capacity)
Chose Curated:
- β Quality guaranteed
- β Zero maintenance
- β Optimized performance
- β Less flexibility
- Mitigation: Use codebase search for project-specific patterns
Chose Functional:
- β Easy composition
- β Easy testing
- β Easy parallelization
- β Steeper learning curve
- Mitigation: Clear patterns and examples
Learn more about the implementation:
- MEP Design Philosophy - Design principles
- Codebase Search - Using Starcode in practice
- Knowledge Base - Curated guidelines system
- Agent Framework - Functional agent composition
Last Updated: 2025-10-30 | Edit this page | Report Issues