Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions service/Service.AspNetCore/WebAPIEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Microsoft.KernelMemory.DocumentStorage;
using Microsoft.KernelMemory.HTTP;
using Microsoft.KernelMemory.Service.AspNetCore.Models;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;

namespace Microsoft.KernelMemory.Service.AspNetCore;
Expand Down Expand Up @@ -108,8 +109,7 @@ public static RouteHandlerBuilder AddPostUploadEndpoint(
})
.WithName("UploadDocument")
.WithDisplayName("UploadDocument")
.WithOpenApi(
operation =>
.WithOpenApi(operation =>
{
operation.Summary = "Upload a new document to the knowledge base";
operation.Description = "Upload a document consisting of one or more files to extract memories from. The extraction process happens asynchronously. If a document with the same ID already exists, it will be overwritten and the memories previously extracted will be updated.";
Expand All @@ -136,15 +136,27 @@ public static RouteHandlerBuilder AddPostUploadEndpoint(
},
["tags"] = new OpenApiSchema
{
Type = "object",
AdditionalProperties = new OpenApiSchema { Type = "string" },
Description = "Tags to apply to the memories extracted from the files."
Type = "array",
Items = new OpenApiSchema { Type = "string" },
Description = "Tags to apply to the memories extracted from the files.",
Example = new OpenApiArray
{
new OpenApiString("group:abc123"),
new OpenApiString("user:xyz")
}
},
["steps"] = new OpenApiSchema
{
Type = "array",
Items = new OpenApiSchema { Type = "string" },
Description = "How to process the files, e.g. how to extract/chunk etc."
Description = "How to process the files, e.g. how to extract/chunk etc.",
Example = new OpenApiArray
{
new OpenApiString("extract"),
new OpenApiString("partition"),
new OpenApiString("gen_embeddings"),
new OpenApiString("save_records"),
}
},
["files"] = new OpenApiSchema
{
Expand All @@ -157,6 +169,11 @@ public static RouteHandlerBuilder AddPostUploadEndpoint(
Description = "Files to process and extract memories from."
}
}
},
Encoding =
{
{ "tags", new OpenApiEncoding { Explode = true } },
{ "steps", new OpenApiEncoding { Explode = true } },
}
}
},
Expand Down
28 changes: 23 additions & 5 deletions swagger.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"openapi": "3.0.1",
"openapi": "3.0.4",
"info": {
"title": "Microsoft.KernelMemory.ServiceAssembly",
"version": "1.0"
Expand Down Expand Up @@ -113,18 +113,28 @@
"description": "Unique ID used for import pipeline and document ID."
},
"tags": {
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"type": "string"
},
"description": "Tags to apply to the memories extracted from the files."
"description": "Tags to apply to the memories extracted from the files.",
"example": [
"group:abc123",
"user:xyz"
]
},
"steps": {
"type": "array",
"items": {
"type": "string"
},
"description": "How to process the files, e.g. how to extract/chunk etc."
"description": "How to process the files, e.g. how to extract/chunk etc.",
"example": [
"extract",
"partition",
"gen_embeddings",
"save_records"
]
},
"files": {
"type": "array",
Expand All @@ -135,6 +145,14 @@
"description": "Files to process and extract memories from."
}
}
},
"encoding": {
"tags": {
"explode": true
},
"steps": {
"explode": true
}
}
}
}
Expand Down
14 changes: 12 additions & 2 deletions tools/km-cli/upload-file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ readParameters() {
;;
-t)
shift
TAGS="$TAGS $1"
TAGS+=("$1")
;;
*)
help
Expand Down Expand Up @@ -102,7 +102,17 @@ readParameters "$@"
validateParameters

# Prepare curl command
CMD="curl -v -F 'file1=@\"${FILENAME}\"' -F 'index=\"${INDEXNAME}\"' -F 'documentId=\"${DOCUMENT_ID}\"' -F 'tags=\"${TAGS}\"'"
CMD="curl -v"
CMD="$CMD -F file1=@\"${FILENAME}\""

# Optianal params
[ -n "$INDEXNAME" ] && CMD="$CMD -F index=\"${INDEXNAME}\""
[ -n "$DOCUMENT_ID" ] && CMD="$CMD -F documentId=\"${DOCUMENT_ID}\""

# Add tags
for TAG in "${TAGS[@]}"; do
CMD="$CMD -F tags=\"$TAG\""
done

# Add URL
CMD="$CMD $SERVICE_URL/upload"
Expand Down