asopi tech
asopi techIndie Developer

Asopitech With · Code hosting

GitHub code search with Alopex DB

GitHub code search finds and reads code across repositories on GitHub, the code hosting service. How would we make it with Alopex DB?

Updated: Oct 12, 2026

What the service does

GitHub code search finds and reads your code, your team’s code and open source code. It supports regular expressions, boolean operations, qualifiers and symbol search for function and class definitions. The data is repositories, files, code fragments and symbols.

Where the data lives

  • SQL tables: repositories, files and symbol definitions live in tables. Filtering by language or repository is a SQL condition.
  • Full-text search: a full-text index on file contents finds identifiers and strings.
  • Vectors: per-function embeddings in a vector column answer questions such as “the code that loads the config file”.

Ingesting repositories and extracting symbols are app code.

Deployment

Alopex DB runs as a server that answers the search UI and editor extensions over HTTP and gRPC. As repositories grow, it scales out to an Alopex DB cluster.

Why Alopex DB fits

Code search needs both search by name and search by meaning. Alopex DB combines full-text search, vector search and SQL filters in one query.

See it in code

Files and symbols live in tables; you filter by language and match a name, and also search functions by meaning. Just the code-search core.

import alopex
import numpy as np

db = alopex.Database.open("github.alopex")

# ファイルとシンボルを持つ
db.execute_sql("""
    CREATE TABLE IF NOT EXISTS files (
        id INTEGER PRIMARY KEY,
        repo TEXT,
        lang TEXT,
        filepath TEXT,
        content TEXT,
        embedding VECTOR(4)
    )
""")
db.execute_sql("""
    CREATE TABLE IF NOT EXISTS symbols (
        file_id INTEGER,
        name TEXT,
        kind TEXT
    )
""")

files = [
    (1, "app", "python", "config.py", "def load_config(path):", [0.9, 0.1, 0.0, 0.0]),
    (2, "app", "rust", "config.rs", "fn load_config()", [0.85, 0.15, 0.0, 0.0]),
    (3, "app", "python", "main.py", "def main():", [0.0, 0.0, 0.9, 0.1]),
]
for fid, repo, lang, filepath, content, emb in files:
    db.execute_sql(
        "INSERT INTO files (id, repo, lang, filepath, content, embedding) VALUES (?, ?, ?, ?, ?, ?)",
        [fid, repo, lang, filepath, content, np.array(emb, dtype=np.float32)],
    )
for file_id, name in [(1, "load_config"), (2, "load_config"), (3, "main")]:
    db.execute_sql("INSERT INTO symbols (file_id, name, kind) VALUES (?, ?, ?)", [file_id, name, "function"])

# 言語で絞り、名前でシンボルを探す(SQLの絞り込み+名前の一致)
print("-- python の load_config")
for row in db.execute_sql("""
    SELECT f.filepath, s.name
    FROM symbols AS s
    JOIN files AS f ON f.id = s.file_id
    WHERE f.lang = ? AND s.name = ?
""", ["python", "load_config"]):
    print("  ", row["filepath"], row["name"])

# 「設定を読み込む処理」に近い関数を、意味で探す
print("-- 意味検索")
query = np.array([1.0, 0.0, 0.0, 0.0], dtype=np.float32)
for row in db.execute_sql("""
    SELECT filepath, vector_similarity(embedding, ?, 'cosine') AS score
    FROM files
    ORDER BY score DESC
    LIMIT 2
""", [query]):
    print("  ", round(row["score"], 3), row["filepath"])

Language/repository filters, exact name matches and meaning distance combine in one engine.

Alopex DB combines full-text search, vector search and SQL filters in one query. Try building code search over your own repositories; the quickstart gets you going.