Skip to content

Commit f90ddb9

Browse files
Finish draft of hybrid search, improvements to find enumerators, update find to be fully fluent for consistency
1 parent 9b92bc0 commit f90ddb9

File tree

73 files changed

+69958
-1026
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+69958
-1026
lines changed

src/DataStax.AstraDB.DataApi/Collections/Collection.cs

Lines changed: 141 additions & 105 deletions
Large diffs are not rendered by default.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright DataStax, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
using System.Collections.Generic;
18+
using System.Linq;
19+
using System.Text.Json.Serialization;
20+
21+
namespace DataStax.AstraDB.DataApi.Core;
22+
23+
/// <summary>
24+
/// Configuration for the analyzer
25+
/// </summary>
26+
public class AnalyzerOptions
27+
{
28+
/// <summary>
29+
/// Tokenizer configuration
30+
/// </summary>
31+
[JsonPropertyName("tokenizer")]
32+
public TokenizerOptions Tokenizer { get; set; } = new();
33+
34+
/// <summary>
35+
/// List of filters to apply
36+
/// </summary>
37+
[JsonIgnore]
38+
public List<string> Filters { get; set; } = new();
39+
40+
/// <summary>
41+
/// List of character filters to apply
42+
/// </summary>
43+
[JsonPropertyName("charFilters")]
44+
public List<string> CharacterFilters { get; set; } = new();
45+
46+
[JsonPropertyName("filters")]
47+
[JsonInclude]
48+
internal List<FilterOptions> FilterOptions
49+
{
50+
get
51+
{
52+
return Filters.Select(f => new FilterOptions() { Name = f }).ToList();
53+
}
54+
}
55+
}

src/DataStax.AstraDB.DataApi/Core/CollectionDefinition.cs

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,30 +44,48 @@ public class CollectionDefinition
4444
[JsonPropertyName("indexing")]
4545
public IndexingOptions Indexing { get; set; }
4646

47+
/// <summary>
48+
/// Lexical analysis options for the collection
49+
/// </summary>
50+
[JsonPropertyName("lexical")]
51+
public LexicalOptions Lexical { get; set; }
52+
53+
/// <summary>
54+
/// Reranking options for the collection
55+
/// </summary>
56+
[JsonPropertyName("rerank")]
57+
public RerankOptions Rerank { get; set; }
58+
4759
internal static CollectionDefinition Create<T>()
60+
{
61+
return CheckAddDefinitionsFromAttributes<T>(new CollectionDefinition());
62+
}
63+
64+
internal static CollectionDefinition CheckAddDefinitionsFromAttributes<T>(CollectionDefinition definition)
4865
{
4966
Type type = typeof(T);
5067
PropertyInfo idProperty = null;
5168
DocumentIdAttribute idAttribute = null;
5269

53-
CollectionDefinition definition = new();
54-
55-
foreach (var property in type.GetProperties())
70+
if (definition.DefaultId == null)
5671
{
57-
var attr = property.GetCustomAttribute<DocumentIdAttribute>();
58-
if (attr != null)
72+
foreach (var property in type.GetProperties())
5973
{
60-
idProperty = property;
61-
idAttribute = attr;
62-
break;
74+
var attr = property.GetCustomAttribute<DocumentIdAttribute>();
75+
if (attr != null)
76+
{
77+
idProperty = property;
78+
idAttribute = attr;
79+
break;
80+
}
6381
}
64-
}
6582

66-
if (idProperty != null)
67-
{
68-
if (idAttribute.DefaultIdType.HasValue)
83+
if (idProperty != null)
6984
{
70-
definition.DefaultId = new DefaultIdOptions() { Type = idAttribute.DefaultIdType.Value };
85+
if (idAttribute.DefaultIdType.HasValue)
86+
{
87+
definition.DefaultId = new DefaultIdOptions() { Type = idAttribute.DefaultIdType.Value };
88+
}
7189
}
7290
}
7391

src/DataStax.AstraDB.DataApi/Core/Commands/Command.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ internal T Deserialize<T>(string input)
202202
deserializeOptions.Converters.Add(new DateTimeConverter<DateTime>());
203203
}
204204
deserializeOptions.Converters.Add(new IpAddressConverter());
205+
deserializeOptions.Converters.Add(new AnalyzerOptionsConverter());
205206

206207
return JsonSerializer.Deserialize<T>(input, deserializeOptions);
207208
}
@@ -302,6 +303,9 @@ private async Task<T> RunCommandAsync<T>(HttpMethod method, bool runSynchronousl
302303
}
303304
else
304305
{
306+
responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
307+
MaybeLogDebugMessage("Response Status Code: {StatusCode}", response.StatusCode);
308+
MaybeLogDebugMessage("Content: {Content}", responseContent);
305309
throw new HttpRequestException($"Request to failed with status code {response.StatusCode}.");
306310
}
307311
}

src/DataStax.AstraDB.DataApi/Core/Commands/DataApiKeywords.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ internal static class DataApiKeywords
2828
internal const string Slice = "$slice";
2929
internal const string Similarity = "$similarity";
3030
internal const string Vector = "$vector";
31+
internal const string Lexical = "$lexical";
32+
internal const string Hybrid = "$hybrid";
3133
internal const string SortVector = "sortVector";
3234
internal const string Vectorize = "$vectorize";
3335
internal const string Binary = "$binary";

0 commit comments

Comments
 (0)