Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Unhandled exception. System.Text.Json.JsonException: '0x00' is an invalid start of a value #920

Open
biapar opened this issue Dec 2, 2024 · 2 comments
Labels
bug Something isn't working triage

Comments

@biapar
Copy link

biapar commented Dec 2, 2024

Context / Scenario

I use LLAMASharp + KernelMemory with PDF analysis. I try with a long PDF. When I query the model, I've this error.
I import the docs with:

 await memory.ImportDocumentAsync(documentPaths[I],
                    steps: Constants.PipelineWithoutSummary);

  SimpleFileStorageConfig storageConfig = new()
                                                {
                                                    Directory = StorageFolder,
                                                    StorageType = FileSystemTypes.Disk,
                                                };

        
        SimpleVectorDbConfig vectorDbConfig = new()
                                              {
                                                  Directory = StorageFolder,
                                                  StorageType = FileSystemTypes.Disk,
                                              };

What happened?

After a prompt:

Error on JSON Read:
Unhandled exception. System.Text.Json.JsonException: '0x00' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0.
---> System.Text.Json.JsonReaderException: '0x00' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0.
at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan1 bytes) at System.Text.Json.Utf8JsonReader.ConsumeValue(Byte marker) at System.Text.Json.Utf8JsonReader.ReadFirstToken(Byte first) at System.Text.Json.Utf8JsonReader.ReadSingleSegment() at System.Text.Json.Utf8JsonReader.Read() at System.Text.Json.Serialization.JsonConverter1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
--- End of inner exception stack trace ---
at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, JsonReaderException ex)
at System.Text.Json.Serialization.JsonConverter1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state) at System.Text.Json.Serialization.Metadata.JsonTypeInfo1.Deserialize(Utf8JsonReader& reader, ReadStack& state)
at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan1 utf8Json, JsonTypeInfo1 jsonTypeInfo, Nullable1 actualByteCount) at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan1 json, JsonTypeInfo1 jsonTypeInfo) at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options) at Microsoft.KernelMemory.MemoryStorage.DevTools.SimpleVectorDb.GetListAsync(String index, ICollection1 filters, Int32 limit, Boolean withEmbeddings, CancellationToken cancellationToken)+MoveNext()
at Microsoft.KernelMemory.MemoryStorage.DevTools.SimpleVectorDb.GetListAsync(String index, ICollection1 filters, Int32 limit, Boolean withEmbeddings, CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult() at Microsoft.KernelMemory.MemoryStorage.DevTools.SimpleVectorDb.GetSimilarListAsync(String index, String text, ICollection1 filters, Double minRelevance, Int32 limit, Boolean withEmbeddings, CancellationToken cancellationToken)+MoveNext()
at Microsoft.KernelMemory.MemoryStorage.DevTools.SimpleVectorDb.GetSimilarListAsync(String index, String text, ICollection1 filters, Double minRelevance, Int32 limit, Boolean withEmbeddings, CancellationToken cancellationToken)+MoveNext() at Microsoft.KernelMemory.MemoryStorage.DevTools.SimpleVectorDb.GetSimilarListAsync(String index, String text, ICollection1 filters, Double minRelevance, Int32 limit, Boolean withEmbeddings, CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
at Microsoft.KernelMemory.Search.SearchClient.AskAsync(String index, String question, ICollection1 filters, Double minRelevance, IContext context, CancellationToken cancellationToken) at Microsoft.KernelMemory.Search.SearchClient.AskAsync(String index, String question, ICollection1 filters, Double minRelevance, IContext context, CancellationToken cancellationToken)
at Program.ShowAnswer(IKernelMemory memory, String question) in /Users/biagioparuolo/ProjectsOnMac/_BWare360Projects/LLMSharp/LLMSharpDemo/LLMSharpDemo/Program.cs:line 145
at Program.StartUserChatSession(IKernelMemory memory) in /Users/biagioparuolo/ProjectsOnMac/_BWare360Projects/LLMSharp/LLMSharpDemo/LLMSharpDemo/Program.cs:line 251
at Program.Main(String[] args) in /Users/biagioparuolo/ProjectsOnMac/_BWare360Projects/LLMSharp/LLMSharpDemo/LLMSharpDemo/Program.cs:line 132
at Program.

(String[] args)
[1] 11122 abort

Importance

edge case

Platform, Language, Versions

LLAMASharp last ver
Kernel Memory last ver
.NET Core 8
MacOS

Relevant log output

@biapar biapar added bug Something isn't working triage labels Dec 2, 2024
@biapar biapar changed the title [Bug] [Bug]: Unhandled exception. System.Text.Json.JsonException: '0x00' is an invalid start of a value Dec 2, 2024
@dluc
Copy link
Collaborator

dluc commented Dec 2, 2024

hi @biapar could you share how you instantiate the memory object?

@biapar
Copy link
Author

biapar commented Dec 2, 2024

string modelPath = fullPath + "Meta-Llama-3.1-8B-Instruct-Q5_K_M.gguf";
IKernelMemory memory = CreateMemory(modelPath);

if (!StorageExists)
{
var documentFolder = mydirIA + "/IAInstructions/";
string[] documentPaths = Directory.GetFiles(documentFolder, "*.pdf");
Console.WriteLine($"Start Add Info: {DateTime.Now}");
for (int i = 0; i < documentPaths.Length; i++)
{
string path = documentPaths[i];
Stopwatch sw = Stopwatch.StartNew();
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine($"Importing {i + 1} of {documentPaths.Length}: {path}");
await memory.ImportDocumentAsync(documentPaths[i],
steps: Constants.PipelineWithoutSummary);
Console.WriteLine($"Completed in {sw.Elapsed}\n");
}

        Console.WriteLine($"Finish Add Info: {DateTime.Now}");
    }

....

static IKernelMemory CreateMemory(string modelPath)
{
InferenceParams infParams = new()
{
AntiPrompts = ["\n\n"],
MaxTokens = -1,

    };


    LLamaSharpConfig lsConfig = new(modelPath)
    {
        DefaultInferenceParams = infParams,
        ContextSize = 2048,
        GpuLayerCount = 5,
    };

    SearchClientConfig searchClientConfig = new()
    {
        MaxMatchesCount = 100,
        AnswerTokens = 300,
        
    };

    TextPartitioningOptions parseOptions = new()
    {
        MaxTokensPerParagraph = 200,
        MaxTokensPerLine = 60,
        OverlappingTokens = 47
    };

    SimpleFileStorageConfig storageConfig = new()
                                            {
                                                Directory = StorageFolder,
                                                StorageType = FileSystemTypes.Disk,
                                            };

    
    SimpleVectorDbConfig vectorDbConfig = new()
                                          {
                                              Directory = StorageFolder,
                                              StorageType = FileSystemTypes.Disk,
                                          };

    var parametes = new ModelParams(modelPath)
    {
        ContextSize = 4096,
        GpuLayerCount = 30,
        Embeddings = false
    };

    var model = LLamaWeights.LoadFromFile(parametes);

    var embWeights = LLamaWeights.LoadFromFile(new ModelParams(modelPath)
    {
        ContextSize = 4096,
        GpuLayerCount = 30,
        Embeddings = true,
    });


     var context = model.CreateContext(parametes);

    var executor2 = new InteractiveExecutor(context);
    var executor = new StatelessExecutor(model, parametes);
  
    Console.ForegroundColor = ConsoleColor.Blue;
    AnsiConsole.WriteLine($"Kernel memory folder: {StorageFolder}");

    return new KernelMemoryBuilder()
        .WithSimpleFileStorage(storageConfig)
        .WithSimpleVectorDb(vectorDbConfig)
        .WithLLamaSharpTextEmbeddingGeneration(new LLamaSharpTextEmbeddingGenerator(lsConfig, embWeights))
        .WithLLamaSharpTextGeneration(new LlamaSharpTextGenerator(model, context, executor,inferenceParams: infParams))

        // .WithLLamaSharpDefaults(lsConfig)
        .WithSearchClientConfig(searchClientConfig)
        .With(parseOptions)
        .Build();


}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage
Projects
None yet
Development

No branches or pull requests

2 participants