-
-
Notifications
You must be signed in to change notification settings - Fork 12
[Store] Add InMemory #109
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
base: main
Are you sure you want to change the base?
[Store] Add InMemory #109
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea. Thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is super cool - found only smaller items 👍
Thanks already @Guikingone!
foreach ($documents as $document) { | ||
$this->documents[] = $document; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could use array_push
instead of iterating over all documents to add:
foreach ($documents as $document) { | |
$this->documents[] = $document; | |
} | |
array_push($this->documents, $documents); |
callback: fn (VectorDocument $vectorDocument): array => [ | ||
'distance' => $this->cosineSimilarity($vectorDocument, $vector), | ||
'document' => $vectorDocument, | ||
], | ||
array: $this->documents, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
named arguments don't add value here or do I miss something?
callback: fn (VectorDocument $vectorDocument): array => [ | |
'distance' => $this->cosineSimilarity($vectorDocument, $vector), | |
'document' => $vectorDocument, | |
], | |
array: $this->documents, | |
fn (VectorDocument $vectorDocument): array => [ | |
'distance' => $this->cosineSimilarity($vectorDocument, $vector), | |
'document' => $vectorDocument, | |
], | |
$this->documents, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same for the others down below
Hi 👋🏻
This PR aim to introduce an
InMemoryStore
to store vectors (mostly used for tests environments and/or POCs), the implementation is based aroundcosine
similarity (others search algorithms can be used but will requires a dedicated interface likeSearchStrategyInterface
or other).This store also allows to retrieve only a specific amount of items if required.
This store don't use
initialize
as everything is stored in an array.PS: An optimized approach would be to use
fpow
but it requires8.4
so ... Well, maybe for later 😄