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

Bugs in conversations #260

Merged
merged 16 commits into from Jul 27, 2023
Merged

Bugs in conversations #260

merged 16 commits into from Jul 27, 2023

Conversation

javipacheco
Copy link
Contributor

@javipacheco javipacheco commented Jul 20, 2023

This PR tries to resolve 2 bugs:

Bug 1

When we are working in conversations in Xef (remember that we are creating by default the conversionId in CoreAIScope)

The problem is the order of the messages when we are sending the messages to OpenAI

Currently, we are storing the messages in the conversation in the wrong order. When we send the request to OpenAI the messages have the following order:

ASSISTANT: <response>
USER: <question>
ASSISTANT: <response>
USER: <question>

And when we add a new question from the user, we add this message to the end like this:

ASSISTANT: <response>
USER: <question>
ASSISTANT: <response>
USER: <question>
USER: <new-question>

In my tests, this is a problem that sometimes OpenAI isn't responding to the last question, it is responding to the second to last

The right order should be:

USER: <question>
ASSISTANT: <response>
USER: <question>
ASSISTANT: <response>
USER: <new-question>

This PR changes the way that we are storing the conversation in the memory in order to fix that

Note: You can revert the changes in Chat.kt and you will see that the Conversation.kt example gives the same result both times

Bug 2

Resolving this issue

Montagon
Montagon previously approved these changes Jul 20, 2023
victorcrrd
victorcrrd previously approved these changes Jul 20, 2023
Copy link
Contributor

@victorcrrd victorcrrd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the problem comes from here, where memories is being reversed. Those memories include, in some way, the messages that form the chat, and they are included in a way that older (question, answer) pairs go first, and questions go before answers. That is, Q1, A1, ... Qn, An. When reversing memories, we have An, Qn, ..., A1, Q1, so answers go before questions.

I don't know if it's better to reverse the order in which question, answer pairs are added to the memory (what you are doing) or if we should take into account that Chat memories come in pairs and that we should reverse them keeping the relative order of pairs the same (and thus changing that messages function. I guess that for this case, your solution is better.

raulraja
raulraja previously approved these changes Jul 20, 2023
Copy link
Contributor

@raulraja raulraja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad 🙋 , thank you!

@javipacheco
Copy link
Contributor Author

I hadn't noticed the reversed(), it's better to do it like this, thank you @victorcrrd

I have found other 2 bugs in the conversations when we are storing the messages in the LocalVectorStore. I'm fixing them now

@javipacheco javipacheco dismissed stale reviews from raulraja, victorcrrd, and Montagon via 9efef72 July 21, 2023 10:18
@javipacheco javipacheco added the bug Something isn't working label Jul 21, 2023
@javipacheco javipacheco linked an issue Jul 21, 2023 that may be closed by this pull request
@javipacheco javipacheco marked this pull request as ready for review July 21, 2023 10:26
@javipacheco javipacheco changed the title [DRAFT] Bugs in conversations Bugs in conversations Jul 21, 2023
@javipacheco
Copy link
Contributor Author

I have updated the PR with the new fixes and added some tests

@victorcrrd @raulraja could you please review it?

@javipacheco
Copy link
Contributor Author

@victorcrrd @raulraja I have fixed some problems in the order messages on CombinedVectorStore and I have created some tests for this

We are using CombinedVectorStore in contextScope inside Xef. They are important changes in the base code. Could you please review the changes?

raulraja
raulraja previously approved these changes Jul 25, 2023
* format

* syntax error in createMemoryTable query

* being able to connect to db

* added missing test

* added documentation to indicate that timestamp is measured in millis

* modeling timestamp in postgres as a BIGINT instead of a TIMESTAMP to avoid problems

* messages retrieved from postgres were assigned always the same name "role", now it matches the name stored in the database

* getting postgres messages in the right order: from oldest to newest (in the form of a chat)

* added simple test

* specifying more the test

* substituting localhost by IP 0.0.0.0 is fine for this test
@javipacheco
Copy link
Contributor Author

@raulraja I have been talking with @victorcrrd because we are going to change the memories() implementation in order to sort the messages by timestamp

On the other hand, should we review the Lucene implementation? This class is using VectorStore too

@javipacheco
Copy link
Contributor Author

@raulraja @Montagon This PR is ready for review. Here are the changes:

  • When we are getting messages from the VectorStore implementations, the messages are sorted by timestamp
  • Messages are always sent in ascending order
  • We should address the Lucene implementation in a separate PR. We have to include integrations tests for that and this is not the proposal for this PR

Copy link
Contributor

@raulraja raulraja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you!

@javipacheco javipacheco merged commit 7b74452 into main Jul 27, 2023
5 checks passed
@javipacheco javipacheco deleted the conversation-bug branch July 27, 2023 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unexpected (?) behaviour of LocalVectorStore's addMemories
4 participants