Skip to content

Commit 97c4874

Browse files
committed
Add OpenAPI support for document upload endpoint and update dependencies.
1 parent cfcca80 commit 97c4874

File tree

4 files changed

+172
-4
lines changed

4 files changed

+172
-4
lines changed

Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<PackageVersion Include="DocumentFormat.OpenXml" Version="3.2.0" />
1515
<PackageVersion Include="HtmlAgilityPack" Version="1.11.72" />
1616
<PackageVersion Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
17+
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0" />
1718
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.2.2" />
1819
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="9.0.1" />
1920
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="9.0.1" />

service/Service.AspNetCore/Service.AspNetCore.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
<ItemGroup>
1414
<ProjectReference Include="..\..\extensions\KM\KernelMemory\KernelMemory.csproj" />
15+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" />
1516
</ItemGroup>
1617

1718
<PropertyGroup>

service/Service.AspNetCore/WebAPIEndpoints.cs

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using Microsoft.KernelMemory.DocumentStorage;
2121
using Microsoft.KernelMemory.HTTP;
2222
using Microsoft.KernelMemory.Service.AspNetCore.Models;
23+
using Microsoft.OpenApi.Models;
2324

2425
namespace Microsoft.KernelMemory.Service.AspNetCore;
2526

@@ -108,7 +109,63 @@ public static RouteHandlerBuilder AddPostUploadEndpoint(
108109
.WithName("UploadDocument")
109110
.WithDisplayName("UploadDocument")
110111
.WithDescription("Upload a new document to the knowledge base and extract memories from it.")
111-
.WithSummary("Upload a document to the knowledge base and extract memories from it. If a document with the same ID already exists, it will be overwritten and the memories previously extracted will be updated. Note: a document can contain multiple files.")
112+
.WithOpenApi(
113+
operation =>
114+
{
115+
operation.RequestBody = new OpenApiRequestBody
116+
{
117+
Content =
118+
{
119+
["multipart/form-data"] = new OpenApiMediaType
120+
{
121+
Schema = new OpenApiSchema
122+
{
123+
Type = "object",
124+
Properties =
125+
{
126+
["index"] = new OpenApiSchema
127+
{
128+
Type = "string",
129+
Description = "Name of the index where to store memories generated by the files."
130+
},
131+
["documentId"] = new OpenApiSchema
132+
{
133+
Type = "string",
134+
Description = "Unique ID used for import pipeline and document ID."
135+
},
136+
["tags"] = new OpenApiSchema
137+
{
138+
Type = "object",
139+
AdditionalProperties = new OpenApiSchema { Type = "string" },
140+
Description = "Tags to apply to the memories extracted from the files."
141+
},
142+
["steps"] = new OpenApiSchema
143+
{
144+
Type = "array",
145+
Items = new OpenApiSchema { Type = "string" },
146+
Description = "How to process the files, e.g. how to extract/chunk etc."
147+
},
148+
["files"] = new OpenApiSchema
149+
{
150+
Type = "array",
151+
Items = new OpenApiSchema
152+
{
153+
Type = "string",
154+
Format = "binary"
155+
},
156+
Description = "Files to process and extract memories from."
157+
}
158+
}
159+
}
160+
}
161+
},
162+
Description = "Document to upload and extract memories from"
163+
};
164+
operation.Summary = "Upload a new document to the knowledge base";
165+
operation.Description = "Upload a document consisting of one or more files to extract memories from. The extraction process happens asynchronously.";
166+
return operation;
167+
}
168+
)
112169
.Produces<UploadAccepted>(StatusCodes.Status202Accepted)
113170
.Produces<ProblemDetails>(StatusCodes.Status400BadRequest)
114171
.Produces<ProblemDetails>(StatusCodes.Status401Unauthorized)

swagger.json

Lines changed: 112 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,51 @@
9494
"tags": [
9595
"Microsoft.KernelMemory.ServiceAssembly"
9696
],
97-
"summary": "Upload a document to the knowledge base and extract memories from it. If a document with the same ID already exists, it will be overwritten and the memories previously extracted will be updated. Note: a document can contain multiple files.",
98-
"description": "Upload a new document to the knowledge base and extract memories from it.",
97+
"summary": "Upload a new document to the knowledge base",
98+
"description": "Upload a document consisting of one or more files to extract memories from. The extraction process happens asynchronously.",
9999
"operationId": "UploadDocument",
100+
"requestBody": {
101+
"description": "Document to upload and extract memories from",
102+
"content": {
103+
"multipart/form-data": {
104+
"schema": {
105+
"type": "object",
106+
"properties": {
107+
"index": {
108+
"type": "string",
109+
"description": "Name of the index where to store memories generated by the files."
110+
},
111+
"documentId": {
112+
"type": "string",
113+
"description": "Unique ID used for import pipeline and document ID."
114+
},
115+
"tags": {
116+
"type": "object",
117+
"additionalProperties": {
118+
"type": "string"
119+
},
120+
"description": "Tags to apply to the memories extracted from the files."
121+
},
122+
"steps": {
123+
"type": "array",
124+
"items": {
125+
"type": "string"
126+
},
127+
"description": "How to process the files, e.g. how to extract/chunk etc."
128+
},
129+
"files": {
130+
"type": "array",
131+
"items": {
132+
"type": "string",
133+
"format": "binary"
134+
},
135+
"description": "Files to process and extract memories from."
136+
}
137+
}
138+
}
139+
}
140+
}
141+
},
100142
"responses": {
101143
"202": {
102144
"description": "Accepted",
@@ -669,6 +711,13 @@
669711
"type": "string",
670712
"nullable": true
671713
},
714+
"tokenUsage": {
715+
"type": "array",
716+
"items": {
717+
"$ref": "#/components/schemas/TokenUsage"
718+
},
719+
"nullable": true
720+
},
672721
"relevantSources": {
673722
"type": "array",
674723
"items": {
@@ -855,6 +904,53 @@
855904
],
856905
"type": "string"
857906
},
907+
"TokenUsage": {
908+
"type": "object",
909+
"properties": {
910+
"timestamp": {
911+
"type": "string",
912+
"format": "date-time"
913+
},
914+
"serviceType": {
915+
"type": "string",
916+
"nullable": true
917+
},
918+
"modelType": {
919+
"type": "string",
920+
"nullable": true
921+
},
922+
"modelName": {
923+
"type": "string",
924+
"nullable": true
925+
},
926+
"tokenizerTokensIn": {
927+
"type": "integer",
928+
"format": "int32",
929+
"nullable": true
930+
},
931+
"tokenizerTokensOut": {
932+
"type": "integer",
933+
"format": "int32",
934+
"nullable": true
935+
},
936+
"serviceTokensIn": {
937+
"type": "integer",
938+
"format": "int32",
939+
"nullable": true
940+
},
941+
"serviceTokensOut": {
942+
"type": "integer",
943+
"format": "int32",
944+
"nullable": true
945+
},
946+
"serviceReasoningTokens": {
947+
"type": "integer",
948+
"format": "int32",
949+
"nullable": true
950+
}
951+
},
952+
"additionalProperties": false
953+
},
858954
"UploadAccepted": {
859955
"type": "object",
860956
"properties": {
@@ -873,6 +969,19 @@
873969
},
874970
"additionalProperties": false
875971
}
972+
},
973+
"securitySchemes": {
974+
"auth": {
975+
"type": "apiKey",
976+
"description": "The API key to access the API",
977+
"name": "Authorization",
978+
"in": "header"
979+
}
980+
}
981+
},
982+
"security": [
983+
{
984+
"auth": []
876985
}
877-
}
986+
]
878987
}

0 commit comments

Comments
 (0)