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

Pick the first correspondent if search returns multiple #88

Closed

Conversation

skius
Copy link

@skius skius commented Jan 10, 2025

Currently, no correspondent is picked (undefined, to be precise) if the API correspondent search returns multiple results. This change simply picks the first result.

An alternative fix would be to check if the AI generated correspondent exists as a 1:1 match, and if not, force create it instead of picking from the existing list. For my documents there are generally too many correspondents being created and not too few, so I opted for the option in this PR to avoid even more.

@clusterzx
Copy link
Owner

Can you elaborate "Currently, no correspondent is picked (undefined, to be precise) if the API correspondent search returns multiple results. This change simply picks the first result."

You mean the paperless API right? I dont see a case where the exact correspondent could be existing 2 times in Paperless under 2 different correspondent objects.

I tried it right now, went into paperless, created the correspondent "Test", saved, create a new correspondent with "Test" -> error wont let me do that.

Or do you mean the OpenAI API? Never had this happend that it gave me multiple correspondents back.

@skius
Copy link
Author

skius commented Jan 13, 2025

@clusterzx: The paperless API is a substring search. If correspondents "AB" and "AC" exist, then a search for "A" will return both. This project seems to be aware of that in paperlessService, see:

if (results.length > 1) {
console.log(`[DEBUG] Multiple correspondents found:`);
results.forEach(c => {
console.log(`- ID: ${c.id}, Name: ${c.name}`);
});
return results;
}

It's just that the downstream consumers of that method are not:
const existingCorrespondent = await this.searchForExistingCorrespondent(name);
console.log("[DEBUG] Response Correspondent Search: ", existingCorrespondent);
if (existingCorrespondent) {
console.log(`[DEBUG] Found existing correspondent "${name}" with ID ${existingCorrespondent.id}`);
return existingCorrespondent;
}

This PR fixes that and makes them Array-aware.

@clusterzx
Copy link
Owner

Oh true sorry, I did miss to implement this completly in all cases.
I thank you for the hint, but I will do it another style.

Next commit you can see the changes here and tell me what you think about it. Have to change some other things.

clusterzx added a commit that referenced this pull request Jan 13, 2025
Fixed #116

Fixed #115

Fixed #98

Fixed #106 again

Implemented #74
(/app/logs)

Implemented #88

Added a loggerService.js to log all messages to a txt and html file
@skius
Copy link
Author

skius commented Jan 13, 2025

Thanks, looks good to me!

@skius skius closed this Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants