Skip to content

Commit 06c5b09

Browse files
committed
Merge branch 'features/refine-knowledge-service' of https://github.com/iceljc/BotSharp into features/refine-knowledge-service
2 parents 06977ff + 043d27f commit 06c5b09

64 files changed

Lines changed: 485 additions & 1643 deletions

File tree

Some content is hidden

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

src/Infrastructure/BotSharp.Abstraction/Graph/IGraphKnowledgeService.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/Infrastructure/BotSharp.Abstraction/Knowledges/Enums/KnowledgeBaseType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ public static class KnowledgeBaseType
55
public static string QuestionAnswer = "question-answer";
66
public static string Document = "document";
77
public static string Taxonomy = "taxonomy";
8-
public static string SemanticGraph = "semantic_graph";
8+
public static string SemanticGraph = "semantic-graph";
99
}

src/Infrastructure/BotSharp.Abstraction/Knowledges/IKnowledgeFileOrchestrator.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using BotSharp.Abstraction.Knowledges.Filters;
2-
using BotSharp.Abstraction.Knowledges.Options;
32
using BotSharp.Abstraction.Knowledges.Responses;
43

54
namespace BotSharp.Abstraction.Knowledges;
@@ -15,8 +14,21 @@ public interface IKnowledgeFileOrchestrator
1514
/// <param name="files"></param>
1615
/// <param name="options"></param>
1716
/// <returns></returns>
18-
Task<UploadKnowledgeResponse> UploadFilesToKnowledge(string collectionName, IEnumerable<ExternalFileModel> files, KnowledgeFileHandleOptions? options = null);
19-
17+
Task<UploadKnowledgeResponse> UploadFilesToKnowledge(string collectionName,
18+
IEnumerable<ExternalFileModel> files, KnowledgeFileHandleOptions? options = null);
19+
20+
/// <summary>
21+
/// Import file content to knowledgebase without saving the file
22+
/// </summary>
23+
/// <param name="collectionName"></param>
24+
/// <param name="fileName"></param>
25+
/// <param name="fileSource"></param>
26+
/// <param name="contents"></param>
27+
/// <param name="options"></param>
28+
/// <returns></returns>
29+
Task<bool> ImportFileContentToKnowledge(string collectionName, string fileName, string fileSource,
30+
IEnumerable<string> contents, ImportKnowledgeFileOptions? options = null);
31+
2032
/// <summary>
2133
/// Delete one file and its related knowledge in the collection
2234
/// </summary>

src/Infrastructure/BotSharp.Abstraction/Knowledges/IKnowledgeOrchestrator.cs

Lines changed: 0 additions & 59 deletions
This file was deleted.
Lines changed: 50 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,61 @@
1-
using BotSharp.Abstraction.Graph.Models;
2-
using BotSharp.Abstraction.Graph.Options;
3-
using BotSharp.Abstraction.Knowledges.Filters;
1+
using BotSharp.Abstraction.Knowledges.Models;
42
using BotSharp.Abstraction.Knowledges.Options;
5-
using BotSharp.Abstraction.Knowledges.Responses;
6-
using BotSharp.Abstraction.VectorStorage.Models;
7-
using BotSharp.Abstraction.VectorStorage.Options;
83

94
namespace BotSharp.Abstraction.Knowledges;
105

116
public interface IKnowledgeService
127
{
13-
#region Vector
14-
//Task<bool> ExistVectorCollection(string collectionName);
15-
//Task<bool> CreateVectorCollection(string collectionName, string collectionType, VectorCollectionCreateOptions options);
16-
//Task<bool> DeleteVectorCollection(string collectionName);
17-
//Task<IEnumerable<VectorCollectionConfig>> GetVectorCollections(string? type = null);
18-
//Task<VectorCollectionDetails?> GetVectorCollectionDetails(string collectionName);
19-
//Task<IEnumerable<VectorSearchResult>> SearchVectorKnowledge(string query, string collectionName, VectorSearchOptions options);
20-
//Task<StringIdPagedItems<VectorSearchResult>> GetPagedVectorCollectionData(string collectionName, VectorFilter filter);
21-
//Task<IEnumerable<VectorCollectionData>> GetVectorCollectionData(string collectionName, IEnumerable<string> ids, VectorQueryOptions? options = null);
22-
//Task<bool> DeleteVectorCollectionData(string collectionName, string id);
23-
//Task<bool> DeleteVectorCollectionAllData(string collectionName);
24-
//Task<bool> CreateVectorCollectionData(string collectionName, VectorCreateModel create);
25-
//Task<bool> UpdateVectorCollectionData(string collectionName, VectorUpdateModel update);
26-
//Task<bool> UpsertVectorCollectionData(string collectionName, VectorUpdateModel update);
27-
#endregion
8+
string KnowledgeType { get; }
289

29-
//#region Document
30-
///// <summary>
31-
///// Save documents and their contents to knowledgebase
32-
///// </summary>
33-
///// <param name="collectionName"></param>
34-
///// <param name="files"></param>
35-
///// <param name="option"></param>
36-
///// <returns></returns>
37-
//Task<UploadKnowledgeResponse> UploadDocumentsToKnowledge(string collectionName, IEnumerable<ExternalFileModel> files, KnowledgeFileHandleOptions? options = null);
38-
///// <summary>
39-
///// Save document content to knowledgebase without saving the document
40-
///// </summary>
41-
///// <param name="collectionName"></param>
42-
///// <param name="fileName"></param>
43-
///// <param name="fileSource"></param>
44-
///// <param name="contents"></param>
45-
///// <param name="refData"></param>
46-
///// <returns></returns>
47-
//Task<bool> ImportDocumentContentToKnowledge(string collectionName, string fileName, string fileSource, IEnumerable<string> contents,
48-
// DocMetaRefData? refData = null, Dictionary<string, VectorPayloadValue>? payload = null);
49-
///// <summary>
50-
///// Delete one document and its related knowledge in the collection
51-
///// </summary>
52-
///// <param name="collectionName"></param>
53-
///// <param name="fileId"></param>
54-
///// <returns></returns>
55-
//Task<bool> DeleteKnowledgeDocument(string collectionName, Guid fileId);
56-
///// <summary>
57-
///// Delete all documents and their related knowledge in the collection
58-
///// </summary>
59-
///// <param name="collectionName"></param>
60-
///// <param name="filter"></param>
61-
///// <returns></returns>
62-
//Task<bool> DeleteKnowledgeDocuments(string collectionName, KnowledgeFileFilter filter);
63-
//Task<PagedItems<KnowledgeFileModel>> GetPagedKnowledgeDocuments(string collectionName, KnowledgeFileFilter filter);
64-
//Task<FileBinaryDataModel> GetKnowledgeDocumentBinaryData(string collectionName, Guid fileId);
65-
//#endregion
10+
#region Collection
11+
Task<bool> ExistCollection(string collectionName, KnowledgeCollectionOptions options)
12+
=> Task.FromResult(false);
13+
Task<bool> CreateCollection(string collectionName, CollectionCreateOptions options)
14+
=> Task.FromResult(false);
15+
Task<bool> DeleteCollection(string collectionName, KnowledgeCollectionOptions options)
16+
=> Task.FromResult(false);
17+
Task<IEnumerable<KnowledgeCollectionConfig>> GetCollections(KnowledgeCollectionOptions options)
18+
=> Task.FromResult(Enumerable.Empty<KnowledgeCollectionConfig>());
19+
Task<KnowledgeCollectionDetails?> GetCollectionDetails(string collectionName, KnowledgeCollectionOptions options)
20+
=> Task.FromResult<KnowledgeCollectionDetails?>(null);
21+
#endregion
6622

67-
//#region Snapshot
68-
//Task<IEnumerable<VectorCollectionSnapshot>> GetVectorCollectionSnapshots(string collectionName);
69-
//Task<VectorCollectionSnapshot?> CreateVectorCollectionSnapshot(string collectionName);
70-
//Task<BinaryData> DownloadVectorCollectionSnapshot(string collectionName, string snapshotFileName);
71-
//Task<bool> RecoverVectorCollectionFromSnapshot(string collectionName, string snapshotFileName, BinaryData snapshotData);
72-
//Task<bool> DeleteVectorCollectionSnapshot(string collectionName, string snapshotName);
73-
//#endregion
23+
#region Data
24+
Task<IEnumerable<KnowledgeExecuteResult>> ExecuteQuery(string query, string collectionName, KnowledgeExecuteOptions options)
25+
=> Task.FromResult(Enumerable.Empty<KnowledgeExecuteResult>());
26+
Task<StringIdPagedItems<KnowledgeCollectionData>> GetPagedCollectionData(string collectionName, KnowledgeFilter filter)
27+
=> Task.FromResult(new StringIdPagedItems<KnowledgeCollectionData>());
28+
Task<IEnumerable<KnowledgeCollectionData>> GetCollectionData(string collectionName, IEnumerable<string> ids, KnowledgeQueryOptions? options = null)
29+
=> Task.FromResult(Enumerable.Empty<KnowledgeCollectionData>());
30+
Task<bool> DeleteCollectionData(string collectionName, string id, KnowledgeCollectionOptions? options)
31+
=> Task.FromResult(false);
32+
Task<bool> DeleteCollectionData(string collectionName, KnowledgeCollectionOptions? options)
33+
=> Task.FromResult(false);
34+
Task<bool> CreateCollectionData(string collectionName, KnowledgeCreateModel create)
35+
=> Task.FromResult(false);
36+
Task<bool> UpdateCollectionData(string collectionName, KnowledgeUpdateModel update)
37+
=> Task.FromResult(false);
38+
Task<bool> UpsertCollectionData(string collectionName, KnowledgeUpdateModel update)
39+
=> Task.FromResult(false);
40+
#endregion
7441

75-
//#region Index
76-
//Task<SuccessFailResponse<string>> CreateVectorCollectionPayloadIndexes(string collectionName, IEnumerable<CollectionIndexOptions> options);
77-
//Task<SuccessFailResponse<string>> DeleteVectorCollectionPayloadIndexes(string collectionName, IEnumerable<CollectionIndexOptions> options);
78-
//#endregion
42+
#region Index
43+
Task<SuccessFailResponse<string>> CreateIndexes(string collectionName, KnowledgeIndexOptions options)
44+
=> Task.FromResult(new SuccessFailResponse<string>());
45+
Task<SuccessFailResponse<string>> DeleteIndexes(string collectionName, KnowledgeIndexOptions options)
46+
=> Task.FromResult(new SuccessFailResponse<string>());
47+
#endregion
7948

49+
#region Snapshot
50+
Task<IEnumerable<KnowledgeCollectionSnapshot>> GetCollectionSnapshots(string collectionName, KnowledgeSnapshotOptions? options = null)
51+
=> Task.FromResult(Enumerable.Empty<KnowledgeCollectionSnapshot>());
52+
Task<KnowledgeCollectionSnapshot?> CreateCollectionSnapshot(string collectionName, KnowledgeSnapshotOptions? options = null)
53+
=> Task.FromResult<KnowledgeCollectionSnapshot?>(null);
54+
Task<BinaryData> DownloadCollectionSnapshot(string collectionName, string snapshotFileName, KnowledgeSnapshotOptions? options = null)
55+
=> Task.FromResult(new BinaryData(Array.Empty<byte>()));
56+
Task<bool> RecoverCollectionFromSnapshot(string collectionName, string snapshotFileName, BinaryData snapshotData, KnowledgeSnapshotOptions? options = null)
57+
=> Task.FromResult(false);
58+
Task<bool> DeleteCollectionSnapshot(string collectionName, string snapshotName, KnowledgeSnapshotOptions? options = null)
59+
=> Task.FromResult(false);
60+
#endregion
8061
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using BotSharp.Abstraction.VectorStorage.Models;
2+
3+
namespace BotSharp.Abstraction.Knowledges.Models;
4+
5+
public class KnowledgeCollectionDetails
6+
{
7+
[JsonPropertyName("status")]
8+
public string Status { get; set; }
9+
10+
[JsonPropertyName("payload_schema")]
11+
public List<PayloadSchemaDetail> PayloadSchema { get; set; } = [];
12+
}

src/Infrastructure/BotSharp.Abstraction/Knowledges/Models/KnowledgeCreateModel.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using BotSharp.Abstraction.Knowledges.Options;
21
using BotSharp.Abstraction.VectorStorage.Models;
32

43
namespace BotSharp.Abstraction.Knowledges.Models;

src/Infrastructure/BotSharp.Abstraction/Knowledges/Models/KnowledgeSearchResult.cs renamed to src/Infrastructure/BotSharp.Abstraction/Knowledges/Models/KnowledgeExecuteResult.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
namespace BotSharp.Abstraction.Knowledges.Models;
22

3-
public class KnowledgeSearchResult : KnowledgeCollectionData
3+
public class KnowledgeExecuteResult : KnowledgeCollectionData
44
{
5-
public KnowledgeSearchResult()
5+
public KnowledgeExecuteResult()
66
{
77

88
}
99

10-
public static KnowledgeSearchResult CopyFrom(KnowledgeCollectionData data)
10+
public static KnowledgeExecuteResult CopyFrom(KnowledgeCollectionData data)
1111
{
12-
return new KnowledgeSearchResult
12+
return new KnowledgeExecuteResult
1313
{
1414
Id = data.Id,
1515
Payload = data.Payload,

src/Infrastructure/BotSharp.Abstraction/Knowledges/Models/KnowledgeFilter.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,26 @@ namespace BotSharp.Abstraction.Knowledges.Models;
44

55
public class KnowledgeFilter : StringIdPagination
66
{
7-
[JsonPropertyName("db_provider")]
87
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
98
public string? DbProvider { get; set; }
109

11-
[JsonPropertyName("with_vector")]
1210
public bool WithVector { get; set; }
1311

1412
/// <summary>
1513
/// Filter group: each item contains a logical operator and a list of key-value pairs
1614
/// </summary>
17-
[JsonPropertyName("filter_groups")]
1815
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
1916
public IEnumerable<VectorFilterGroup>? FilterGroups { get; set; }
2017

2118
/// <summary>
2219
/// Order by a specific field
2320
/// </summary>
24-
[JsonPropertyName("order_by")]
2521
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
2622
public VectorSort? OrderBy { get; set; }
2723

2824
/// <summary>
2925
/// Included payload fields
3026
/// </summary>
31-
[JsonPropertyName("fields")]
3227
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
3328
public IEnumerable<string>? Fields { get; set; }
3429
}

src/Infrastructure/BotSharp.Abstraction/Knowledges/Options/GraphKnowledgeSearchOptions.cs renamed to src/Infrastructure/BotSharp.Abstraction/Knowledges/Options/GraphKnowledgeExecuteOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace BotSharp.Abstraction.Knowledges.Options;
22

3-
public class GraphKnowledgeSearchOptions : KnowledgeSearchOptions
3+
public class GraphKnowledgeExecuteOptions : KnowledgeExecuteOptions
44
{
55
public string? GraphId { get; set; }
66
}

0 commit comments

Comments
 (0)