|
| 1 | +// Copyright (c) Ugo Lattanzi. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information. |
| 2 | + |
| 3 | +using System.Threading.Tasks; |
| 4 | + |
| 5 | +namespace StackExchange.Redis.Extensions.Core.Abstractions; |
| 6 | + |
| 7 | +/// <summary> |
| 8 | +/// The Redis Database VectorSet extensions for AI/ML similarity search. |
| 9 | +/// Requires Redis 8.0+. |
| 10 | +/// </summary> |
| 11 | +public partial interface IRedisDatabase |
| 12 | +{ |
| 13 | + /// <summary> |
| 14 | + /// Adds a vector to the VectorSet stored at key. |
| 15 | + /// </summary> |
| 16 | + /// <param name="key">The key of the VectorSet.</param> |
| 17 | + /// <param name="request">The add request containing the member, vector, and optional attributes.</param> |
| 18 | + /// <param name="flag">Behaviour markers associated with a given command.</param> |
| 19 | + /// <returns>True if the member was added, false if it already existed and was updated.</returns> |
| 20 | + Task<bool> VectorSetAddAsync(string key, VectorSetAddRequest request, CommandFlags flag = CommandFlags.None); |
| 21 | + |
| 22 | + /// <summary> |
| 23 | + /// Performs a similarity search against the VectorSet stored at key. |
| 24 | + /// </summary> |
| 25 | + /// <param name="key">The key of the VectorSet.</param> |
| 26 | + /// <param name="query">The search request containing the query vector and parameters.</param> |
| 27 | + /// <param name="flag">Behaviour markers associated with a given command.</param> |
| 28 | + /// <returns>The matching results with scores. The returned Lease must be disposed after use.</returns> |
| 29 | + Task<Lease<VectorSetSimilaritySearchResult>?> VectorSetSimilaritySearchAsync(string key, VectorSetSimilaritySearchRequest query, CommandFlags flag = CommandFlags.None); |
| 30 | + |
| 31 | + /// <summary> |
| 32 | + /// Removes a member from the VectorSet stored at key. |
| 33 | + /// </summary> |
| 34 | + /// <param name="key">The key of the VectorSet.</param> |
| 35 | + /// <param name="member">The member to remove.</param> |
| 36 | + /// <param name="flag">Behaviour markers associated with a given command.</param> |
| 37 | + /// <returns>True if the member was removed, false if it did not exist.</returns> |
| 38 | + Task<bool> VectorSetRemoveAsync(string key, string member, CommandFlags flag = CommandFlags.None); |
| 39 | + |
| 40 | + /// <summary> |
| 41 | + /// Checks if a member exists in the VectorSet stored at key. |
| 42 | + /// </summary> |
| 43 | + /// <param name="key">The key of the VectorSet.</param> |
| 44 | + /// <param name="member">The member to check.</param> |
| 45 | + /// <param name="flag">Behaviour markers associated with a given command.</param> |
| 46 | + /// <returns>True if the member exists.</returns> |
| 47 | + Task<bool> VectorSetContainsAsync(string key, string member, CommandFlags flag = CommandFlags.None); |
| 48 | + |
| 49 | + /// <summary> |
| 50 | + /// Returns the number of members in the VectorSet stored at key. |
| 51 | + /// </summary> |
| 52 | + /// <param name="key">The key of the VectorSet.</param> |
| 53 | + /// <param name="flag">Behaviour markers associated with a given command.</param> |
| 54 | + /// <returns>The cardinality of the VectorSet, or 0 if the key does not exist.</returns> |
| 55 | + Task<long> VectorSetLengthAsync(string key, CommandFlags flag = CommandFlags.None); |
| 56 | + |
| 57 | + /// <summary> |
| 58 | + /// Returns the number of dimensions of vectors in the VectorSet stored at key. |
| 59 | + /// </summary> |
| 60 | + /// <param name="key">The key of the VectorSet.</param> |
| 61 | + /// <param name="flag">Behaviour markers associated with a given command.</param> |
| 62 | + /// <returns>The number of dimensions.</returns> |
| 63 | + Task<long> VectorSetDimensionAsync(string key, CommandFlags flag = CommandFlags.None); |
| 64 | + |
| 65 | + /// <summary> |
| 66 | + /// Gets the JSON attributes associated with a member in the VectorSet. |
| 67 | + /// </summary> |
| 68 | + /// <param name="key">The key of the VectorSet.</param> |
| 69 | + /// <param name="member">The member to retrieve attributes for.</param> |
| 70 | + /// <param name="flag">Behaviour markers associated with a given command.</param> |
| 71 | + /// <returns>The JSON attributes string, or null if the member has no attributes.</returns> |
| 72 | + Task<string?> VectorSetGetAttributesJsonAsync(string key, string member, CommandFlags flag = CommandFlags.None); |
| 73 | + |
| 74 | + /// <summary> |
| 75 | + /// Sets JSON attributes on a member in the VectorSet. |
| 76 | + /// </summary> |
| 77 | + /// <param name="key">The key of the VectorSet.</param> |
| 78 | + /// <param name="member">The member to set attributes on.</param> |
| 79 | + /// <param name="attributesJson">The JSON attributes string.</param> |
| 80 | + /// <param name="flag">Behaviour markers associated with a given command.</param> |
| 81 | + /// <returns>True if the attributes were set.</returns> |
| 82 | + Task<bool> VectorSetSetAttributesJsonAsync(string key, string member, string attributesJson, CommandFlags flag = CommandFlags.None); |
| 83 | + |
| 84 | + /// <summary> |
| 85 | + /// Returns information about the VectorSet stored at key. |
| 86 | + /// </summary> |
| 87 | + /// <param name="key">The key of the VectorSet.</param> |
| 88 | + /// <param name="flag">Behaviour markers associated with a given command.</param> |
| 89 | + /// <returns>Information about the VectorSet.</returns> |
| 90 | + Task<VectorSetInfo?> VectorSetInfoAsync(string key, CommandFlags flag = CommandFlags.None); |
| 91 | + |
| 92 | + /// <summary> |
| 93 | + /// Returns a random member from the VectorSet stored at key. |
| 94 | + /// </summary> |
| 95 | + /// <param name="key">The key of the VectorSet.</param> |
| 96 | + /// <param name="flag">Behaviour markers associated with a given command.</param> |
| 97 | + /// <returns>A random member, or null if the VectorSet is empty.</returns> |
| 98 | + Task<RedisValue> VectorSetRandomMemberAsync(string key, CommandFlags flag = CommandFlags.None); |
| 99 | + |
| 100 | + /// <summary> |
| 101 | + /// Returns multiple random members from the VectorSet stored at key. |
| 102 | + /// </summary> |
| 103 | + /// <param name="key">The key of the VectorSet.</param> |
| 104 | + /// <param name="count">The number of random members to return.</param> |
| 105 | + /// <param name="flag">Behaviour markers associated with a given command.</param> |
| 106 | + /// <returns>An array of random members.</returns> |
| 107 | + Task<RedisValue[]> VectorSetRandomMembersAsync(string key, long count, CommandFlags flag = CommandFlags.None); |
| 108 | + |
| 109 | + /// <summary> |
| 110 | + /// Returns the approximate vector for a member in the VectorSet. |
| 111 | + /// </summary> |
| 112 | + /// <param name="key">The key of the VectorSet.</param> |
| 113 | + /// <param name="member">The member to retrieve the vector for.</param> |
| 114 | + /// <param name="flag">Behaviour markers associated with a given command.</param> |
| 115 | + /// <returns>The approximate vector as a Lease of floats. Must be disposed after use. Null if member not found.</returns> |
| 116 | + Task<Lease<float>?> VectorSetGetApproximateVectorAsync(string key, string member, CommandFlags flag = CommandFlags.None); |
| 117 | + |
| 118 | + /// <summary> |
| 119 | + /// Returns the links (neighbors) for a member in the VectorSet's HNSW graph. |
| 120 | + /// </summary> |
| 121 | + /// <param name="key">The key of the VectorSet.</param> |
| 122 | + /// <param name="member">The member to retrieve links for.</param> |
| 123 | + /// <param name="flag">Behaviour markers associated with a given command.</param> |
| 124 | + /// <returns>The linked member names. The returned Lease must be disposed after use.</returns> |
| 125 | + Task<Lease<RedisValue>?> VectorSetGetLinksAsync(string key, string member, CommandFlags flag = CommandFlags.None); |
| 126 | + |
| 127 | + /// <summary> |
| 128 | + /// Returns the links (neighbors) with similarity scores for a member in the VectorSet's HNSW graph. |
| 129 | + /// </summary> |
| 130 | + /// <param name="key">The key of the VectorSet.</param> |
| 131 | + /// <param name="member">The member to retrieve links for.</param> |
| 132 | + /// <param name="flag">Behaviour markers associated with a given command.</param> |
| 133 | + /// <returns>The links with scores. The returned Lease must be disposed after use.</returns> |
| 134 | + Task<Lease<VectorSetLink>?> VectorSetGetLinksWithScoresAsync(string key, string member, CommandFlags flag = CommandFlags.None); |
| 135 | +} |
0 commit comments