Skip to content

Commit afd9517

Browse files
ilopezlunasourcery-ai[bot]doringeman
authored
feat: add semantic search demo with embeddings and REST API (#399)
* feat: add semantic search demo with embeddings and REST API * Update demos/embeddings/search.js Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> * feat: update README and server to support automatic download of pre-generated embeddings index * feat: update embeddings index URL and improve search placeholder examples * Update demos/embeddings/indexer.js Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> * Update demos/embeddings/search.js Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> * Update demos/embeddings/README.md Co-authored-by: Dorin-Andrei Geman <[email protected]> * Update demos/embeddings/README.md Co-authored-by: Dorin-Andrei Geman <[email protected]> * Update demos/embeddings/README.md Co-authored-by: Dorin-Andrei Geman <[email protected]> * feat: update README with instructions for pulling the ai/qwen3-embedding model --------- Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> Co-authored-by: Dorin-Andrei Geman <[email protected]>
1 parent 74d3080 commit afd9517

File tree

9 files changed

+2833
-0
lines changed

9 files changed

+2833
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ pkg/distribution/bin/
1919

2020
llamacpp/build
2121
llamacpp/install
22+
23+
.DS_Store

demos/embeddings/.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Dependencies
2+
node_modules/
3+
4+
# Generated embeddings index
5+
embeddings-index.json
6+
7+
# Logs
8+
npm-debug.log*
9+
yarn-debug.log*
10+
yarn-error.log*
11+
12+
# OS files
13+
.DS_Store
14+
Thumbs.db

demos/embeddings/README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Codebase Embeddings Demo
2+
3+
This demo application enables semantic search over your codebase using AI embeddings. Ask natural language questions like "Where is the model packaging code?" and get relevant code snippets with similarity scores.
4+
5+
## Quick Start (Recommended) ⚡
6+
7+
The demo automatically downloads a pre-generated embeddings index from a [GitHub Gist](https://gist.githubusercontent.com/ilopezluna/235518ab315c23275c90c5cddb1375b8/raw/df541734b3f4843f99b8ce34f4cee240addde08f/embeddings-index.json) on first run, so you can start searching immediately without waiting for indexing.
8+
9+
### Prerequisites
10+
11+
- **Node.js** (version 18 or higher)
12+
- **Docker Model Runner** running on port 12434
13+
14+
### Installation
15+
16+
```bash
17+
# Pull ai/qwen3-embedding:0.6B-F16
18+
docker model pull ai/qwen3-embedding:0.6B-F16
19+
20+
# Navigate to the demo directory
21+
cd demos/embeddings
22+
23+
# Install dependencies
24+
npm install
25+
26+
# Start the server
27+
npm start
28+
```
29+
30+
The server will automatically:
31+
1. Check if an embeddings index exists locally
32+
2. If not found, download the pre-generated index from the Gist
33+
3. Load the index and start the server
34+
4. Open your browser to http://localhost:3000
35+
36+
**That's it!** You can now search the codebase with natural language queries.
37+
38+
### About the Pre-generated Index
39+
40+
The pre-generated embeddings index:
41+
- Contains embeddings for the entire Docker Model Runner codebase
42+
- Generated using the `ai/qwen3-embedding:0.6B-F16` model
43+
- Hosted on GitHub Gist for easy access
44+
45+
**Note**: The pre-generated index represents a snapshot of the codebase. If you've made local code changes and want search results to reflect them, see the "Generate Your Own Index" section below.
46+
47+
---
48+
49+
## Generate Your Own Index 🔨
50+
51+
Want to generate fresh embeddings for your local codebase?
52+
53+
```bash
54+
# Navigate to demo directory
55+
cd demos/embeddings
56+
57+
# Run the indexer (takes ~20 minutes)
58+
npm run index
59+
```
60+
61+
This will:
62+
1. Scan all source files in the project (respecting .gitignore)
63+
2. Generate embeddings for each file/chunk
64+
3. Save the index to `embeddings-index.json`
65+
66+
After indexing completes, start the server:
67+
```bash
68+
npm start
69+
```
70+
71+
---
72+
73+
## Additional Resources
74+
75+
- [Docker Model Runner Documentation](https://docs.docker.com/ai/model-runner/)
76+
- [Embedding Models on Docker Hub](https://hub.docker.com/u/ai?page=1&search=embed)
77+
- [Pre-generated Index Gist](https://gist.githubusercontent.com/ilopezluna/235518ab315c23275c90c5cddb1375b8/raw/df541734b3f4843f99b8ce34f4cee240addde08f/embeddings-index.json)
78+
- [Cosine Similarity Explanation](https://en.wikipedia.org/wiki/Cosine_similarity)

0 commit comments

Comments
 (0)