Client examples for querying codebase indexes stored in SQLite-vec and Qdrant.
These scripts demonstrate how to:
- Connect to SQLite-vec or Qdrant databases
- Generate embeddings for search queries
- Search for code chunks or git commits
- Display results with similarity scores
search-demo.js- JavaScript/Node.js interactive searchsearch-demo.py- Python interactive searchsearch-test.js- Non-interactive quick test
search-commits.js- Search git commits analyzed by LLM
# No dependencies needed - uses native fetch!
# Get all commits (max 5)
node search-commits.js codebase-908e5cbf73d44edcbc
# Search commits semantically
node search-commits.js codebase-908e5cbf73d44edcbc "cleanup and refactoring"# Install dependencies
npm install better-sqlite3 sqlite-vec dotenv
# Run the demo
node search-demo.js
# Or make it executable
chmod +x search-demo.js
./search-demo.js# Install dependencies
pip install sqlite-vec requests python-dotenv
# Run the demo
python search-demo.py
# Or make it executable
chmod +x search-demo.py
./search-demo.pyBoth scripts read configuration from environment variables (.env file):
# Embedding Provider
EMBED_PROVIDER=openai-compatible
# Model Configuration
EMBED_MODEL=Qwen/Qwen3-Embedding-8B
EMBED_BASE_URL=https://api.studio.nebius.com/v1/
EMBED_API_KEY=your-api-key-here
# Vector Dimension (must match your indexed data)
EMBED_DIMENSION=4096- openai - Official OpenAI API
- openai-compatible - OpenAI-compatible APIs (Nebius, Together, etc.)
- ollama - Local Ollama instance
-
Start the script:
node search-demo.js # or python search-demo.py -
Enter database path when prompted:
Enter the path to the SQLite database: .codebase/vectors.db -
Enter search queries:
Enter your search query: authentication function -
View results:
Found 10 results: ================================================================================ 1. src/auth/login.ts (lines 15-45) Score: 87.32% | Distance: 0.1268 ------------------------------------------------------------------------------ export async function authenticateUser(username: string, password: string) { const user = await db.users.findOne({ username }); if (!user) { throw new Error('User not found'); } -
Exit:
Enter your search query: exit
Both scripts read embedding configuration from environment variables.
// JavaScript
const db = new Database(dbPath);
sqlite_vec.load(db);# Python
conn = sqlite3.connect(db_path)
sqlite_vec.load(conn)// JavaScript
const queryVector = await generateEmbedding(query);# Python
query_vector = generate_embedding(query)SELECT
file_path,
code_chunk,
start_line,
end_line,
distance
FROM code_vectors
WHERE embedding MATCH ?
ORDER BY distance
LIMIT 10Results are sorted by similarity score (1 - distance) and displayed with:
- File path and line numbers
- Similarity score (0-100%)
- Code preview (first 5 lines)
- 90-100% - Excellent match (almost identical)
- 70-90% - Good match (semantically similar)
- 50-70% - Moderate match (related concepts)
- <50% - Weak match (loosely related)
- Lower distance = Higher similarity
- Distance is converted to score:
score = 1 - distance - For cosine distance: 0 = identical, 2 = opposite
JavaScript:
const results = searchDatabase(db, tableName, queryVector, 20); // 20 resultsPython:
results = search_database(conn, table_name, query_vector, limit=20) # 20 resultsJavaScript:
const query = `
SELECT * FROM ${tableName}
WHERE embedding MATCH ?
AND file_path LIKE 'src/auth/%'
ORDER BY distance
LIMIT ?
`;Python:
query = f"""
SELECT * FROM {table_name}
WHERE embedding MATCH ?
AND file_path LIKE 'src/auth/%'
ORDER BY distance
LIMIT ?
"""// JavaScript
const results = searchResults.filter(r => r.score >= 0.7); // 70% minimum# Python
results = [r for r in results if r['score'] >= 0.7] # 70% minimum- Check the path you entered
- Make sure you've indexed your codebase first:
codesql -start .
- The database might not be a SQLite-vec database
- Try indexing your codebase first
- Check your
EMBED_API_KEYis correct - Verify
EMBED_BASE_URLis accessible - Ensure
EMBED_MODELis valid for your provider
EMBED_DIMENSIONmust match the dimension used during indexing- Check your
.envfile - Common dimensions: 1536 (OpenAI small), 4096 (Qwen)
Query: user authentication login
Query: SQL query database connection
Query: try catch error handling
Query: REST API endpoint route handler
Same as the main project.