-
Couldn't load subscription status.
- Fork 70
add Feature of AI-powered search #637
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
Open
nipeone
wants to merge
8
commits into
meilisearch:main
Choose a base branch
from
nipeone:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6f58f38
add Feature of AI-powered search
nipeone 220c788
Merge branch 'main' into main
nipeone dd12e31
Make the types of embedders uniform
nipeone c108ed1
add embedder setting tests, customSearch test
nipeone 1b83480
Merge branch 'main' of https://github.com/nipeone/meilisearch-dotnet
nipeone 272feaf
Merge branch 'meilisearch:main' into main
nipeone e9cbc09
Merge branch 'main' into main
Strift afb2110
Merge branch 'main' into main
Strift File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| using System.Text.Json; | ||
| using System; | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace Meilisearch.Converters | ||
| { | ||
| /// <summary> | ||
| /// | ||
| /// </summary> | ||
| public class EmbedderSourceConverter: JsonConverter<EmbedderSource> | ||
| { | ||
| /// <summary> | ||
| /// | ||
| /// </summary> | ||
| /// <param name="reader"></param> | ||
| /// <param name="typeToConvert"></param> | ||
| /// <param name="options"></param> | ||
| /// <returns></returns> | ||
| public override EmbedderSource Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
| { | ||
| var value = reader.GetString(); | ||
| switch (value) | ||
| { | ||
| case "openAi": | ||
| return EmbedderSource.OpenAi; | ||
| case "huggingFace": | ||
| return EmbedderSource.HuggingFace; | ||
| case "ollama": | ||
| return EmbedderSource.Ollama; | ||
| case "rest": | ||
| return EmbedderSource.Rest; | ||
| case "userProvided": | ||
| return EmbedderSource.UserProvided; | ||
| default: | ||
| return EmbedderSource.Empty; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// | ||
| /// </summary> | ||
| /// <param name="writer"></param> | ||
| /// <param name="value"></param> | ||
| /// <param name="options"></param> | ||
| public override void Write(Utf8JsonWriter writer, EmbedderSource value, JsonSerializerOptions options) | ||
| { | ||
| string stringValue; | ||
| switch (value) | ||
| { | ||
| case EmbedderSource.OpenAi: | ||
| stringValue = "openAi"; | ||
| break; | ||
| case EmbedderSource.HuggingFace: | ||
| stringValue = "huggingFace"; | ||
| break; | ||
| case EmbedderSource.Ollama: | ||
| stringValue = "ollama"; | ||
| break; | ||
| case EmbedderSource.Rest: | ||
| stringValue = "rest"; | ||
| break; | ||
| case EmbedderSource.UserProvided: | ||
| stringValue = "userProvided"; | ||
| break; | ||
| default: | ||
| stringValue = string.Empty; | ||
| break; | ||
| } | ||
| writer.WriteStringValue(stringValue); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| using System.Collections.Generic; | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| using Meilisearch.Converters; | ||
|
|
||
| namespace Meilisearch | ||
| { | ||
| /// <summary> | ||
| /// Configure at least one embedder to use AI-powered search. | ||
| /// </summary> | ||
| public class Embedder | ||
| { | ||
| /// <summary> | ||
| /// Use source to configure an embedder's source. | ||
| /// This field is mandatory. | ||
| /// </summary> | ||
| [JsonPropertyName("source")] | ||
| public EmbedderSource Source { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Meilisearch queries url to generate vector embeddings for queries and documents. | ||
| /// </summary> | ||
| [JsonPropertyName("url")] | ||
| public string Url { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Authentication token Meilisearch should send with each request to the embedder. | ||
| /// </summary> | ||
| [JsonPropertyName("apiKey")] | ||
| public string ApiKey { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The model your embedder uses when generating vectors. | ||
| /// </summary> | ||
| [JsonPropertyName("model")] | ||
| public string Model { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// documentTemplate is a string containing a Liquid template. | ||
| /// </summary> | ||
| [JsonPropertyName("documentTemplate")] | ||
| public string DocumentTemplate { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The maximum size of a rendered document template. Longer texts are truncated to fit the configured limit. | ||
| /// </summary> | ||
| [JsonPropertyName("documentTemplateMaxBytes")] | ||
| public int? DocumentTemplateMaxBytes { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Number of dimensions in the chosen model. If not supplied, Meilisearch tries to infer this value. | ||
| /// </summary> | ||
| [JsonPropertyName("dimensions")] | ||
| public int? Dimensions { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Use this field to use a specific revision of a model. | ||
| /// </summary> | ||
| [JsonPropertyName("revision")] | ||
| public string Revision { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Use distribution when configuring an embedder to correct the returned | ||
| /// _rankingScores of the semantic hits with an affine transformation | ||
| /// </summary> | ||
| [JsonPropertyName("distribution")] | ||
| public Distribution Distribution { get; set; } | ||
|
|
||
| ///// <summary> | ||
| ///// request must be a JSON object with the same structure | ||
| ///// and data of the request you must send to your rest embedder. | ||
| ///// </summary> | ||
| //[JsonPropertyName("request")] | ||
| //public object Request { get; set; } | ||
|
|
||
| ///// <summary> | ||
| ///// response must be a JSON object with the same structure | ||
| ///// and data of the response you expect to receive from your rest embedder. | ||
| ///// </summary> | ||
| //[JsonPropertyName("response")] | ||
| //public object Response { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// When set to true, compresses vectors by representing each dimension with 1-bit values. | ||
| /// </summary> | ||
| [JsonPropertyName("binaryQuantized")] | ||
| public bool? BinaryQuantized { get; set; } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Configuring distribution requires a certain amount of trial and error, | ||
| /// in which you must perform semantic searches and monitor the results. | ||
| /// Based on their rankingScores and relevancy, add the observed mean and sigma values for that index. | ||
| /// </summary> | ||
| public class Distribution | ||
| { | ||
| /// <summary> | ||
| /// a number between 0 and 1 indicating the semantic score of "somewhat relevant" | ||
| /// hits before using the distribution setting. | ||
| /// </summary> | ||
| [JsonPropertyName("mean")] | ||
| public float? Mean { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// a number between 0 and 1 indicating the average absolute difference in | ||
| /// _rankingScores between "very relevant" hits and "somewhat relevant" hits, | ||
| /// and "somewhat relevant" hits and "irrelevant hits". | ||
| /// </summary> | ||
| [JsonPropertyName("sigma")] | ||
| public float? Sigma { get; set; } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// | ||
| /// </summary> | ||
| [JsonConverter(typeof(EmbedderSourceConverter))] | ||
| public enum EmbedderSource | ||
| { | ||
| /// <summary> | ||
| /// empty source | ||
| /// </summary> | ||
| Empty, | ||
| /// <summary> | ||
| /// openAi source | ||
| /// </summary> | ||
| OpenAi, | ||
| /// <summary> | ||
| /// guggingFace source | ||
| /// </summary> | ||
| HuggingFace, | ||
| /// <summary> | ||
| /// ollama source | ||
| /// </summary> | ||
| Ollama, | ||
| /// <summary> | ||
| /// use rest to auto-generate embeddings with any embedder offering a REST API. | ||
| /// </summary> | ||
| Rest, | ||
| /// <summary> | ||
| /// You may also configure a userProvided embedder. | ||
| /// In this case, you must manually include vector data in your documents' _vectors field. | ||
| /// </summary> | ||
| UserProvided | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| using System.Collections.Generic; | ||
| using System.Net.Http.Json; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
|
|
||
| using Meilisearch.Extensions; | ||
| namespace Meilisearch | ||
| { | ||
| public partial class Index | ||
| { | ||
| /// <summary> | ||
| /// Gets the embedders setting. | ||
| /// </summary> | ||
| /// <param name="cancellationToken">The cancellation token for this call.</param> | ||
| /// <returns>Returns the embedders setting.</returns> | ||
| public async Task<Dictionary<string, Embedder>> GetEmbeddersAsync(CancellationToken cancellationToken = default) | ||
| { | ||
| return await _http.GetFromJsonAsync<Dictionary<string, Embedder>>($"indexes/{Uid}/settings/embedders", cancellationToken: cancellationToken) | ||
| .ConfigureAwait(false); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Updates the embedders setting. | ||
| /// </summary> | ||
| /// <param name="embedders">Collection of embedders</param> | ||
| /// <param name="cancellationToken">The cancellation token for this call.</param> | ||
| /// <returns>Returns the task info of the asynchronous task.</returns> | ||
| public async Task<TaskInfo> UpdateEmbeddersAsync(Dictionary<string, Embedder> embedders, CancellationToken cancellationToken = default) | ||
| { | ||
| var responseMessage = | ||
| await _http.PatchAsJsonAsync($"indexes/{Uid}/settings/embedders", embedders, Constants.JsonSerializerOptionsRemoveNulls, cancellationToken: cancellationToken) | ||
| .ConfigureAwait(false); | ||
| return await responseMessage.Content.ReadFromJsonAsync<TaskInfo>(cancellationToken: cancellationToken) | ||
| .ConfigureAwait(false); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Resets the embedders setting. | ||
| /// </summary> | ||
| /// <param name="cancellationToken">The cancellation token for this call.</param> | ||
| /// <returns>Returns the task info of the asynchronous task.</returns> | ||
| public async Task<TaskInfo> ResetEmbeddersAsync(CancellationToken cancellationToken = default) | ||
| { | ||
| var response = await _http.DeleteAsync($"indexes/{Uid}/settings/embedders", cancellationToken) | ||
| .ConfigureAwait(false); | ||
|
|
||
| return await response.Content.ReadFromJsonAsync<TaskInfo>(cancellationToken: cancellationToken).ConfigureAwait(false); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Method reference in error message doesn't match the current method.
The error message references
GetDocumentsAsyncinstead ofGetSimilarDocumentsAsync, which could be confusing during troubleshooting.📝 Committable suggestion