Skip to content

Conversation

Copy link

Copilot AI commented Nov 7, 2025

Builds a working demonstration of vector embeddings and semantic similarity search using Node.js and Fastify.

Implementation

Core modules:

  • embeddings.js - Text-to-vector conversion using character/word features (10-dimensional), cosine similarity, and Euclidean distance
  • vectorStore.js - In-memory vector store with similarity search and CRUD operations
  • server.js - Fastify REST API with 9 endpoints for document management and search

API endpoints:

POST /documents    # Add document with auto-generated embedding
POST /search       # Semantic search with cosine or euclidean similarity
GET  /documents    # List all documents
GET  /stats        # Store statistics
POST /demo         # Load sample data

Example usage:

# Load demo data
curl -X POST http://localhost:3000/demo

# Search for similar documents
curl -X POST http://localhost:3000/search \
  -H "Content-Type: application/json" \
  -d '{"query": "programming languages", "topK": 3}'

Testing:

  • test.js - 6 test cases covering embedding generation, similarity calculations, and store operations
  • Run via npm test

Notes

  • Embeddings use simplified text features for demonstration; production would use pre-trained models (OpenAI, Cohere, sentence-transformers)
  • CORS configured with origin: true for demo; restrict in production
  • Requires Node.js ≥18.11.0 for --watch flag support
Original prompt

node.js fastify template application, logic for demo of vector embeddings and retrieval


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits November 7, 2025 19:36
Co-authored-by: bculleec <145722460+bculleec@users.noreply.github.com>
…nd add Node version requirement

Co-authored-by: bculleec <145722460+bculleec@users.noreply.github.com>
Co-authored-by: bculleec <145722460+bculleec@users.noreply.github.com>
Copilot AI changed the title [WIP] Add vector embeddings and retrieval logic for demo Implement Fastify vector embeddings and semantic search demo Nov 7, 2025
Copilot AI requested a review from bculleec November 7, 2025 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants