Skip to content

Commit

Permalink
cleanup instant vector search recipe (#22)
Browse files Browse the repository at this point in the history
* cleanup instant vector search recipe

* Update instant-vector-search/README.md

Co-authored-by: Ryan Fox-Tyler <[email protected]>

---------

Co-authored-by: Ryan Fox-Tyler <[email protected]>
  • Loading branch information
johnymontana and ryanfoxtyler authored Dec 9, 2024
1 parent 740639c commit 81db89b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Code recipes for cooking with [Modus](https://github.com/hypermodeinc/modus), th

## 🚀 Getting started with Modus

For more infromation on getting started with Modus, check out [the docs](https://docs.hypermode.com/modus/overview).
For more information on getting started with Modus, check out [the docs](https://docs.hypermode.com/modus/overview).

## 📺 Video walkthroughs

Expand All @@ -16,5 +16,6 @@ The following recipes have associated recorded content:
| [modus-getting-started](modus-getting-started/) | [Getting Started With Modus video](https://www.youtube.com/watch?v=3CcJTXTmz88) |
| [modushack-data-models](modushack-data-models/) | [ModusHack: Working With Data & AI Models livestream](https://www.youtube.com/watch?v=gB-v7YWwkCw&list=PLzOEKEHv-5e3zgRGzDysyUm8KQklHQQgi&index=3) |
| [modus-press](modus-press/) | Coming soon |
| [dgraph-101](dgraph-101/) | [Working with Dgraph in Modus](https://youtu.be/Z2fB-nBf4Wo) |
| [function-calling](function-calling/) | [Use LLM function calling aka tools in Modus.](https://youtu.be/afFk7JzSIm0) |
| [dgraph-101](dgraph-101/) | [Working with Dgraph in Modus](https://youtu.be/Z2fB-nBf4Wo) |
| [function-calling](function-calling/) | [Use LLM function calling aka tools in Modus.](https://youtu.be/afFk7JzSIm0) |
| [instant-vector-search](instant-vector-search) | [Instant vector search with Modus & Hypermode](https://www.youtube.com/watch?v=4H_xPTUbwL8) |
30 changes: 18 additions & 12 deletions instant-vector-search/README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
# instant-vector-search

A simplified template demonstrating how to build instant vector search using Hypermode and Modus. This project showcases how to configure collections, embed data, and deploy APIs to perform real-time vector search with minimal setup.
A simplified example demonstrating how to build instant vector search using Hypermode and Modus. This project showcases how to configure collections, embed data, and deploy APIs to perform real-time vector search with minimal setup.

## Guide

Check out the guide on how to create a project using this template:
[Instant Vector Search Guide](TODO)
Check out the blog post on how to create a project using this example:
[How to Build an Instant Vector Search App using Hypermode & Modus](https://hypermode.com/blog/instant-vector-search-guide)

## Semantic Search in Action

This template demonstrates how instant vector search can enhance your application by generating embeddings from user queries and performing vector searches in less than 200ms.
This example demonstrates how instant vector search can enhance your application by generating embeddings from user queries and performing vector searches in less than 200ms.

## How to Use the Template

Fork or clone this repository to get started:

```
git clone https://github.com/hypermodeinc/instant-vector-search.git
cd instant-vector-search
```bash
git clone https://github.com/hypermodeinc/modus-recipes.git
cd modus-recipes/instant-vector-search
```

Install Modus CLI:

```
```bash
npm install -g @hypermode/modus-cli
```

## Initialize and deploy your app:
## Initialize and deploy your app

You can deploy using either the Hypermode Console or Hyp CLI.

Expand All @@ -37,10 +37,16 @@ Option 1: Hypermode Console

Option 2: Hyp CLI

- Run the following command to import and deploy your app:
- Install the Hyp CLI

```bash
npm install -g @hypermode/hyp-cli
```
hyp init

- Run the following command to import and deploy your app:

```bash
hyp link
```

## Uploading Data
Expand All @@ -57,7 +63,7 @@ Once your data is in place, the embeddings will be generated automatically, and

You can test the API via the Query page in the Hypermode Console. Run a sample vector search query:

```
```GraphQL
query {
search(query: "your search term here")
}
Expand Down
9 changes: 9 additions & 0 deletions instant-vector-search/assembly/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const textsCollection = "texts";
const searchMethod = "searchMethod1";
const embeddingModelName = "minilm";

/**
* Add text(s) to the collection
*/
export function upsertTexts(ids: string[], texts: string[]): string[] {
const errors: string[] = [];

Expand All @@ -24,6 +27,9 @@ export function upsertTexts(ids: string[], texts: string[]): string[] {
return ids;
}

/**
* Perform a vector search using an embedding of the input string
*/
export function search(query: string): string[] {
const searchResults = collections.search(
textsCollection,
Expand All @@ -48,6 +54,9 @@ export function search(query: string): string[] {
return searchTexts;
}

/**
* Embed the input text(s) using the miniLM embedding model
*/
export function miniLMEmbed(texts: string[]): f32[][] {
const model = models.getModel<EmbeddingsModel>(embeddingModelName);
const input = model.createInput(texts);
Expand Down

0 comments on commit 81db89b

Please sign in to comment.