Skip to content

Commit

Permalink
test: handle the condition where the namespace is not present in the …
Browse files Browse the repository at this point in the history
…namespace list if there are no more vectors associated with it
  • Loading branch information
neon-sunset committed Sep 25, 2024
1 parent c7cc61a commit feabe70
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions test/DataTestFixtureBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public abstract class DataTestFixtureBase<T> : IAsyncLifetime
where T : ITransport<T>
{
public const int MaxAttemptCount = 100;
public const int DelayInterval = 500;
public const int DelayInterval = 250;
public abstract string IndexName { get; }

public PineconeClient Pinecone { get; private set; } = null!;
Expand Down Expand Up @@ -120,8 +120,10 @@ public virtual async Task<uint> InsertAndWait(IEnumerable<Vector> vectors, strin

public async Task DeleteAndWait(IEnumerable<string> ids, string? indexNamespace = null)
{
indexNamespace ??= "";

var stats = await Index.DescribeStats();
var vectorCountBefore = stats.Namespaces.Single(x => x.Name == (indexNamespace ?? "")).VectorCount;
var vectorCountBefore = stats.Namespaces.Single(x => x.Name == indexNamespace).VectorCount;

var attemptCount = 0;
await Index.Delete(ids, indexNamespace);
Expand All @@ -131,7 +133,13 @@ public async Task DeleteAndWait(IEnumerable<string> ids, string? indexNamespace
await Task.Delay(DelayInterval);
attemptCount++;
stats = await Index.DescribeStats();
vectorCount = stats.Namespaces.Single(x => x.Name == (indexNamespace ?? "")).VectorCount;
// When using REST transport, it appears that the namespace is no longer returned in the stats
// if the last vector(s) are deleted from it. Here, we handle that by treating it as zero.
vectorCount = stats.Namespaces
.SingleOrDefault(
x => x.Name == indexNamespace,
new() { Name = indexNamespace, VectorCount = 0 })
.VectorCount;
} while (vectorCount > vectorCountBefore - ids.Count() && attemptCount <= MaxAttemptCount);

if (vectorCount > vectorCountBefore - ids.Count())
Expand Down

0 comments on commit feabe70

Please sign in to comment.