Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 23, 2025

Implements a learnable adapter layer that transforms query vectors to better match relevant chunk vectors based on user feedback. The adapter is a single dense layer initialized as identity matrix, trained via MSE loss when users upvote search results.

Core Components

  • src/models/adapter.ts - MongoDB schema for persisting adapter weights per collection
  • src/service/adapter.ts - TensorFlow.js linear projection with:
    • Identity matrix initialization (no-op until trained)
    • Per-collection model caching
    • Memory-safe tensor lifecycle management
    • Dual storage support: Local file storage (default) or MongoDB (when ADAPTER_USE_MONGO=true)

Integration Points

  • Feedback Consumer - On upvote: retrieves chunk vector from Qdrant, trains adapter to map query → chunk
  • Search Route - Applies learned transformation to query embeddings before vector search
  • Qdrant Service - New retrievePoints() for fetching vectors by ID

Usage Flow

1. User searches: "how to reset password"
2. User upvotes result (chunk_id: abc123)
3. Feedback consumer trains: adapter(query_embedding) → chunk_embedding
4. Future searches use transformed embeddings for better retrieval

Configuration

Environment Variable Default Description
ADAPTER_USE_MONGO false Set to true to use MongoDB for model storage
ADAPTER_STORAGE_PATH ./adapter_models Directory for local file storage

Dependencies

  • Added @tensorflow/tfjs@4.22.0 (no known vulnerabilities)
Original prompt

We want to create a adapter layer (Linear Projection) which morph query vector to match better with appropriate chunk vector in db. Here is how it will work.

  1. Feedback received from owner ( Example Query = Chunk x)
  2. We create embedding of both query and chunk
  3. We will create a sinlge dense layer neural net which will be initialized as identity matrix using tensor flow for nodejs
  4. We will train our model from received feedback to take the query closer to chunk
  5. All the training will take place in feedback consumer
  6. In query route, we will use this model to modify future queries to match better results

Above is the rough idea, let me know if you got it or ask me clarification if you need.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 12 commits December 19, 2025 17:51
Co-authored-by: ankit-programmer <36553178+ankit-programmer@users.noreply.github.com>
Co-authored-by: ankit-programmer <36553178+ankit-programmer@users.noreply.github.com>
…ithout punctuation

Co-authored-by: ankit-programmer <36553178+ankit-programmer@users.noreply.github.com>
Co-authored-by: ankit-programmer <36553178+ankit-programmer@users.noreply.github.com>
…reservation

Co-authored-by: ankit-programmer <36553178+ankit-programmer@users.noreply.github.com>
Co-authored-by: ankit-programmer <36553178+ankit-programmer@users.noreply.github.com>
…-chunking-class

Add semantic chunking strategy using embedding similarity with sliding window
Copilot AI self-assigned this Dec 23, 2025
Copilot AI and others added 2 commits December 23, 2025 17:03
Co-authored-by: ankit-programmer <36553178+ankit-programmer@users.noreply.github.com>
Co-authored-by: ankit-programmer <36553178+ankit-programmer@users.noreply.github.com>
Copilot AI changed the title [WIP] Add adapter layer for query and chunk matching Add Linear Projection adapter layer for feedback-driven query vector transformation Dec 23, 2025
@ankit-programmer
Copy link
Collaborator

@copilot I have updated some code, take a pull and update the adapter service to store the model in local file by default and only use mongo if flag is enabled.

Copilot AI and others added 2 commits December 25, 2025 10:06
…when ADAPTER_USE_MONGO=true

Co-authored-by: ankit-programmer <36553178+ankit-programmer@users.noreply.github.com>
…logging

Co-authored-by: ankit-programmer <36553178+ankit-programmer@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 25, 2025

@copilot I have updated some code, take a pull and update the adapter service to store the model in local file by default and only use mongo if flag is enabled.

Updated the adapter service to use local file storage by default. MongoDB storage is now only used when ADAPTER_USE_MONGO=true is set. Added ADAPTER_STORAGE_PATH env variable to customize storage location (default: ./adapter_models). Changes in commits c441f1a and 00e0c67.

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.

3 participants