- Notifications
You must be signed in to change notification settings - Fork 359
/
Copy pathIMemoryDb.cs
101 lines (92 loc) · 4.04 KB
/
IMemoryDb.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright (c) Microsoft. All rights reserved.
usingSystem.Collections.Generic;
usingSystem.Threading;
usingSystem.Threading.Tasks;
namespaceMicrosoft.KernelMemory.MemoryStorage;
/// <summary>
/// Common interface with all Memory API methods.
/// </summary>
publicinterfaceIMemoryDb
{
/// <summary>
/// Create an index/collection
/// </summary>
/// <param name="index">Index/Collection name</param>
/// <param name="vectorSize">Index/Collection vector size</param>
/// <param name="cancellationToken">Task cancellation token</param>
TaskCreateIndexAsync(
stringindex,
intvectorSize,
CancellationTokencancellationToken=default);
/// <summary>
/// List indexes from the memory DB
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns>List of indexes</returns>
Task<IEnumerable<string>>GetIndexesAsync(CancellationTokencancellationToken=default);
/// <summary>
/// Delete an index/collection
/// </summary>
/// <param name="index">Index/Collection name</param>
/// <param name="cancellationToken">Task cancellation token</param>
TaskDeleteIndexAsync(
stringindex,
CancellationTokencancellationToken=default);
/// <summary>
/// Insert/Update a vector + payload.
/// </summary>
/// <param name="index">Index/Collection name</param>
/// <param name="record">Vector + payload to save</param>
/// <param name="cancellationToken">Task cancellation token</param>
/// <returns>Record ID</returns>
/// <exception cref="IndexNotFoundException">Error returned if the index where to write doesn't exist</exception>
Task<string>UpsertAsync(
stringindex,
MemoryRecordrecord,
CancellationTokencancellationToken=default);
/// <summary>
/// Get list of similar vectors (+payload)
/// </summary>
/// <param name="index">Index/Collection name</param>
/// <param name="text">Text being searched</param>
/// <param name="filters">Values to match in the field used for tagging records (the field must be a list of strings)</param>
/// <param name="minRelevance">Minimum Cosine Similarity required</param>
/// <param name="limit">Max number of results</param>
/// <param name="withEmbeddings">Whether to include vector in the result</param>
/// <param name="cancellationToken">Task cancellation token</param>
/// <returns>List of similar vectors, starting from the most similar</returns>
IAsyncEnumerable<(MemoryRecord,double)>GetSimilarListAsync(
stringindex,
stringtext,
ICollection<MemoryFilter>?filters=null,
doubleminRelevance=0,
intlimit=1,
boolwithEmbeddings=false,
CancellationTokencancellationToken=default);
/// <summary>
/// Get list of records having a field matching a given value.
/// E.g. searching vectors by tag, for deletions.
/// </summary>
/// <param name="index">Index/Collection name</param>
/// <param name="filters">Values to match in the field used for tagging records (the field must be a list of strings)</param>
/// <param name="limit">Max number of records to return</param>
/// <param name="withEmbeddings">Whether to include vector in the result</param>
/// <param name="cancellationToken">Task cancellation token</param>
/// <returns>List of records</returns>
IAsyncEnumerable<MemoryRecord>GetListAsync(
stringindex,
ICollection<MemoryFilter>?filters=null,
intlimit=1,
boolwithEmbeddings=false,
CancellationTokencancellationToken=default);
/// <summary>
/// Delete a memory record
/// </summary>
/// <param name="index">Index/Collection name</param>
/// <param name="record">Record to delete. Most memory DBs require only the record ID to be set.</param>
/// <param name="cancellationToken">Task cancellation token</param>
TaskDeleteAsync(
stringindex,
MemoryRecordrecord,
CancellationTokencancellationToken=default);
}