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

Fix #75 - handle missing indexes #76

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/KernelMemory.MemoryStorage.SqlServer/SqlServerMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
";

cmd.Parameters.AddWithValue("@index", index);
cmd.Parameters.AddWithValue("@key", record.Id);

Check warning on line 164 in src/KernelMemory.MemoryStorage.SqlServer/SqlServerMemory.cs

View workflow job for this annotation

GitHub Actions / build

In externally visible method 'Task SqlServerMemory.DeleteAsync(string index, MemoryRecord record, CancellationToken cancellationToken = default(CancellationToken))', validate parameter 'record' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1062)

await cmd.ExecuteNonQueryAsync(cancellationToken).ConfigureAwait(false);
}
Expand Down Expand Up @@ -220,8 +220,14 @@
}

/// <inheritdoc/>
public async IAsyncEnumerable<MemoryRecord> GetListAsync(string index, ICollection<MemoryFilter>? filters = null, int limit = 1, bool withEmbeddings = false, CancellationToken cancellationToken = default)

Check warning on line 223 in src/KernelMemory.MemoryStorage.SqlServer/SqlServerMemory.cs

View workflow job for this annotation

GitHub Actions / build

Async-iterator 'SqlServerMemory.GetListAsync(string, ICollection<MemoryFilter>?, int, bool, CancellationToken)' has one or more parameters of type 'CancellationToken' but none of them is decorated with the 'EnumeratorCancellation' attribute, so the cancellation token parameter from the generated 'IAsyncEnumerable<>.GetAsyncEnumerator' will be unconsumed
{
if (!(await this.DoesIndexExistsAsync(index, cancellationToken).ConfigureAwait(false)))
{
// Index does not exist
yield break;
}

string queryColumns = "[key], [payload], [tags]";

if (withEmbeddings)
Expand Down Expand Up @@ -268,8 +274,14 @@
}

/// <inheritdoc/>
public async IAsyncEnumerable<(MemoryRecord, double)> GetSimilarListAsync(string index, string text, ICollection<MemoryFilter>? filters = null, double minRelevance = 0, int limit = 1, bool withEmbeddings = false, CancellationToken cancellationToken = default)

Check warning on line 277 in src/KernelMemory.MemoryStorage.SqlServer/SqlServerMemory.cs

View workflow job for this annotation

GitHub Actions / build

Async-iterator 'SqlServerMemory.GetSimilarListAsync(string, string, ICollection<MemoryFilter>?, double, int, bool, CancellationToken)' has one or more parameters of type 'CancellationToken' but none of them is decorated with the 'EnumeratorCancellation' attribute, so the cancellation token parameter from the generated 'IAsyncEnumerable<>.GetAsyncEnumerator' will be unconsumed
{
if (!(await this.DoesIndexExistsAsync(index, cancellationToken).ConfigureAwait(false)))
{
// Index does not exist
yield break;
}

Embedding embedding = await this._embeddingGenerator.GenerateEmbeddingAsync(text, cancellationToken).ConfigureAwait(false);

string queryColumns = "[id], [payload], [tags]";
Expand Down Expand Up @@ -347,6 +359,12 @@
/// <inheritdoc/>
public async Task<string> UpsertAsync(string index, MemoryRecord record, CancellationToken cancellationToken = default)
{
if (!(await this.DoesIndexExistsAsync(index, cancellationToken).ConfigureAwait(false)))
{
// Index does not exist
return string.Empty;
}

using var connection = new SqlConnection(this._config.ConnectionString);

await connection.OpenAsync(cancellationToken)
Expand Down
Loading