public async Task GlobalSetup() { _path = Guid.NewGuid().ToString(); var plain = await PlainIndex(); _lmdb = new LmdbIndex(_path); foreach (var field in plain.Fields) { _lmdb.AddField(field); } foreach (var(k, v) in plain.FieldVectors) { _lmdb.AddFieldVector(k, v); } foreach (var(k, v) in plain.InvertedIndex) { _lmdb.AddInvertedIndexEntry(k, v); } Index = new DelegatedIndex(_lmdb, plain.Pipeline); }
private DelegatedIndex CopyIndex(Lunr.Index index) { var path = _tempDir.NewDirectory(); var lmdb = new LmdbIndex(path); foreach (var field in index.Fields) { Assert.True(lmdb.AddField(field)); } foreach (var(k, v) in index.FieldVectors) { Assert.True(lmdb.AddFieldVector(k, v)); } foreach (var(k, v) in index.InvertedIndex) { Assert.True(lmdb.AddInvertedIndexEntry(k, v)); } var idx = new DelegatedIndex(lmdb, index.Pipeline); return(idx); }
public void Can_persist_vectors() { const string key = "Key"; using var index = new LmdbIndex(_tempDir.NewDirectory()); Vector vector = VectorFrom(4, 5, 6); Assert.Equal(Math.Sqrt(77), vector.Magnitude); var addedVector = index.AddFieldVector(key, vector, CancellationToken.None); Assert.True(addedVector); var getByKey = index.GetFieldVectorByKey(key); Assert.NotNull(getByKey); Assert.Equal(Math.Sqrt(77), getByKey?.Magnitude); var getKeys = index.GetFieldVectorKeys().ToList(); Assert.Single(getKeys); Assert.Equal(getKeys[0], key); var removedVector = index.RemoveFieldVector(key, CancellationToken.None); Assert.True(removedVector); var noVector = index.GetFieldVectorByKey(key); Assert.Null(noVector); var noVectorKeys = index.GetFieldVectorKeys(CancellationToken.None); Assert.Empty(noVectorKeys); }