Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add embedding && index embedding #86

Conversation

LittleLittleCloud
Copy link
Collaborator

@LittleLittleCloud LittleLittleCloud commented May 16, 2023

Purpose

This PR enables Azure Document vector search solution. It makes two major change

  • during indexing, it uses text-embedding-ada model to generate embeddings for all sections
  • when retrieving relavent doc, it uses the same embedding model to generate embedding for query

TODO

  • replace text-embedding-ada with local embedding model
  • update .bicep to create embedding model during provision.

fix issue

Does this introduce a breaking change?

[x] Yes
[ ] No

Pull Request Type

What kind of change does this Pull Request introduce?

[ ] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Documentation content changes
[ ] Other... Please describe:

How to Test

  • Get the code
git clone [repo-address]
cd [repo-name]
git checkout [branch-name]
npm install
  • Test the code

What to Check

Verify that the following are valid

  • ...

Other Information

Copy link
Collaborator

@luisquintanilla luisquintanilla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great @LittleLittleCloud. Added minor nit. Do we know if the OpenAI endpoint that's deployed by azd/bicep contains an embedding model or is this something we need to account for?

app/prepdocs/PrepareDocs/Program.Options.cs Outdated Show resolved Hide resolved
@luisquintanilla
Copy link
Collaborator

@LittleLittleCloud let's do this for this PR. We won't merge into main. Let's create a separate branch for it and update the READMEs to point to that branch if they're interested in trying out the vector support.

app/backend/Extensions/SearchClientExtensions.cs Outdated Show resolved Hide resolved
@@ -6,7 +6,8 @@ internal static class SearchClientExtensions
{
internal static async Task<string> QueryDocumentsAsync(
this SearchClient searchClient,
string query,
string? query = null,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since now query can be null (e.g. pure vector search), you need to account for this below when creating search options that use semantic ranking. If query == null then it's an error to enable reranking (SearchQueryType.Semantic) since we need to have a text query for that.

@@ -75,7 +75,7 @@ public class ReadRetrieveReadChatService

// step 2
// use query to search related docs
var documentContents = await _searchClient.QueryDocumentsAsync(query.Result, overrides, cancellationToken);
var documentContents = await _searchClient.QueryDocumentsAsync(query.Result, embedding: null, overrides: overrides, cancellationToken);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why no vectors for the chat case? Seems like it's the most popular scenario, isn't it?

InputType = "query",
}, cancellationToken);
var embedding = questionEmbeddingResponse.Value.Data.First().Embedding.ToArray();
var text = await _searchClient.QueryDocumentsAsync(query: null, embedding: embedding, overrides: overrides, cancellationToken: cancellationToken);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why null for query? We could do hybrid search using both text and vector, it'll yield better results.

Even better, though we may not have time for this right now, we could have an option in the "developer settings" part of the UX that let's the user choose between:

  1. Pure vector search
  2. Pure text search
  3. Hybrid search
  4. For 2 and 3, option to enable semantic

Separately, if the overrides enable semantic search, you can't have the text query == null.

@@ -50,6 +50,8 @@ param gptDeploymentName string = 'davinci'
param gptModelName string = 'text-davinci-003'
param chatGptDeploymentName string = 'chat'
param chatGptModelName string = 'gpt-35-turbo'
param embeddingModelName string = 'text-embedding-ada-002'
param embeddingDeploymentName string = 'embedding'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you might have forgotten to wire up this name to the webapp settings in line ~140 below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those values are saved in the key-vault now. So most of the parameters here are probably unnecessary to set.

@LittleLittleCloud LittleLittleCloud changed the base branch from main to feature/embeddingSearch May 22, 2023 20:21
@LittleLittleCloud LittleLittleCloud merged commit 0a52a89 into Azure-Samples:feature/embeddingSearch Jun 20, 2023
2 checks passed
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.

None yet

3 participants