Skip to content

Commit

Permalink
feat: add hybrid-search
Browse files Browse the repository at this point in the history
  • Loading branch information
NikiforovAll committed Nov 2, 2024
1 parent 4fd19db commit 290e456
Show file tree
Hide file tree
Showing 3 changed files with 364 additions and 802 deletions.
20 changes: 14 additions & 6 deletions src/elasticsearch-getting-started/00-quick-start.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -321,15 +321,22 @@
"source": [
"async Task<float[]> ToEmbedding(string text) {\n",
" GeneratedEmbeddings<Embedding<float>> embeddings = await generator\n",
" .GenerateAsync(text, new EmbeddingGenerationOptions{\n",
" AdditionalProperties = new AdditionalPropertiesDictionary{\n",
" {\"dimensions\", textEmeddingDimension}\n",
" }\n",
" .GenerateAsync([text], new EmbeddingGenerationOptions{\n",
" Dimensions = textEmeddingDimension\n",
" });\n",
"\n",
" return embeddings.First().Vector.ToArray();\n",
"}\n",
"\n",
"async Task<IEnumerable<float[]>> ToEmbeddings(IEnumerable<string> items) {\n",
" GeneratedEmbeddings<Embedding<float>> embeddings = await generator\n",
" .GenerateAsync(items, new EmbeddingGenerationOptions{\n",
" Dimensions = textEmeddingDimension\n",
" });\n",
"\n",
" return embeddings.Select(x => x.Vector.ToArray());\n",
"}\n",
"\n",
"var embedding = await ToEmbedding(\"The quick brown fox jumps over the lazy dog\");\n",
"display($\"Dimensions length = {embedding.Length}\");\n"
]
Expand All @@ -354,9 +361,10 @@
},
"outputs": [],
"source": [
"foreach(var book in books)\n",
"var embeddings = (await ToEmbedding(books.Select(x => x.Title))).ToArray();\n",
"for(var i = 0; i < embeddings.Length; i++)\n",
"{\n",
" book.TitleVector = await ToEmbedding(book.Title);\n",
" books[i].TitleVector = embeddings[i];\n",
"}"
]
},
Expand Down
Loading

0 comments on commit 290e456

Please sign in to comment.