-
Notifications
You must be signed in to change notification settings - Fork 97
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
Add get similar document method #645
Add get similar document method #645
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.
Thank you very much for your PR @the-sinner 🙏 ❤️
|
||
class SimilarDocumentsQuery | ||
{ | ||
private int|string|null $id = null; |
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.
Why null
? this parameter is mandatory
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.
will fix this
$this->index->waitForTask($promise['taskUid']); | ||
} | ||
|
||
public function testBasicSearchWithFilters(): void |
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.
public function testBasicSearchWithFilters(): void | |
public function testBasicSearchWithSimilarDocuments(): void |
->setId($documentId) | ||
); | ||
|
||
self::assertNotNull($response); |
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.
Can we check we have some expected fields in the answer (specific to similar documents query, like id
) even if we don't check the value?
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.
can you share the response format of this api, i could not find it.
i tried running the rc1 locally, however i was getting "Cannot find embedder with name default
"
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 will ask my colleagues next week for having a basic tests with basic documents to make it test simply 😊
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.
Hello!
To use the similar endpoints, you need to:
- enable the
vectorStore
experimental feature - declare at least one embedder in your configuration
For quick sanity tests, the simplest is probably to declare a userProvided
embedder.
The settings could be:
"embedders": {
"manual": {
"source": "userProvided",
"dimensions": 3,
}
}
Then declare a set of documents that contain the _vectors.manual
field, for example:
[
{
"title": "Shazam!",
"release_year": 2019,
"id": "287947",
// Three semantic properties:
// 1. magic, anything that reminds you of magic
// 2. authority, anything that inspires command
// 3. horror, anything that inspires fear or dread
"_vectors": { "manual": [0.8, 0.4, -0.5]},
},
{
"title": "Captain Marvel",
"release_year": 2019,
"id": "299537",
"_vectors": { "manual": [0.6, 0.8, -0.2] },
},
{
"title": "Escape Room",
"release_year": 2019,
"id": "522681",
"_vectors": { "manual": [0.1, 0.6, 0.8] },
},
{
"title": "How to Train Your Dragon: The Hidden World",
"release_year": 2019,
"id": "166428",
"_vectors": { "manual": [0.7, 0.7, -0.4] },
},
{
"title": "All Quiet on the Western Front",
"release_year": 1930,
"id": "143",
"_vectors": { "manual": [-0.5, 0.3, 0.85] },
}
]
The example are from the the engine test file for the similar endpoints.
can you share the response format of this api, i could not find it.
You're right I added the response format to the public usage page, please feel free to ask for more information as needed ☀️
@the-sinner do you think it would be relevant to create a SimilarDocumentsSearchResult file like https://github.com/meilisearch/meilisearch-php/blob/main/src/Search/SearchResult.php? |
@the-sinner can you update tests according to dureuill message? 😇 |
eb312ed
to
7e95ffb
Compare
@curquiza i have added the test case shared by dureuill in the code. |
bd1f46a
to
490bf71
Compare
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.
found the issue, |
@norkunas @curquiza
which one do you think would be better ? In the reference link provided, the given example is using string ids, however the linked documentation allows both string and integer keys. |
Use phpdoc and that's all. People should respect the contract in the same way |
f63abad
to
2fe0b2f
Compare
2fe0b2f
to
6bd9c62
Compare
6bd9c62
to
c64b75a
Compare
c64b75a
to
40f601f
Compare
} | ||
|
||
/** | ||
* @param string[] $attributesToRetrieve an array of attribute names to retrieve |
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.
* @param string[] $attributesToRetrieve an array of attribute names to retrieve | |
* @param list<non-empty-string> $attributesToRetrieve an array of attribute names to retrieve |
} | ||
|
||
/** | ||
* @param string[][] $filter an array of arrays representing filter conditions |
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.
Could this shape be more specific?
$this->id = $id; | ||
} | ||
|
||
public function setOffset(?int $offset): SimilarDocumentsQuery |
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.
public function setOffset(?int $offset): SimilarDocumentsQuery | |
/** | |
* @param non-negative-int $offset | |
*/ | |
public function setOffset(?int $offset): SimilarDocumentsQuery |
return $this; | ||
} | ||
|
||
public function setLimit(?int $limit): SimilarDocumentsQuery |
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.
public function setLimit(?int $limit): SimilarDocumentsQuery | |
/** | |
* @param positive-int $limit | |
*/ | |
public function setLimit(?int $limit): SimilarDocumentsQuery |
return $this; | ||
} | ||
|
||
public function setEmbedder(string $embedder): SimilarDocumentsQuery |
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.
public function setEmbedder(string $embedder): SimilarDocumentsQuery | |
/** | |
* @param non-empty-string $embedder | |
*/ | |
public function setEmbedder(string $embedder): SimilarDocumentsQuery |
} | ||
|
||
/** | ||
* @return array SimilarDocumentsQuery converted to an array with non null fields |
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 still don't see shape defined :)
40f601f
to
90545e8
Compare
Co-authored-by: Tomas Norkūnas <[email protected]>
Co-authored-by: Tomas Norkūnas <[email protected]>
Test failing are expected and due to the new RC |
bbc1116
into
meilisearch:bump-meilisearch-v1.9.0
* Add get similar documents method * Remove null from rankingScoreThreshold * Update src/Contracts/SimilarDocumentsQuery.php Co-authored-by: Tomas Norkūnas <[email protected]> * Update src/Contracts/SimilarDocumentsQuery.php Co-authored-by: Tomas Norkūnas <[email protected]> --------- Co-authored-by: Clémentine <[email protected]> Co-authored-by: Tomas Norkūnas <[email protected]>
Pull Request
Related issue
Fixes #642
What does this PR do?
PR checklist
Please check if your PR fulfills the following requirements:
Thank you so much for contributing to Meilisearch!