Repository navigation
Add meili similar - #32
Conversation
The command carries the fields of `SimilarQuery` as flags, `--id` for the document to compare with and `--embedder` for the similarity to compute, as rules 6 and 7 of the command contract derive them, and `--data` or `--file` carries a whole body that a flag of the same field overrides. The GET twin stays unimplemented, as its exception already said. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Command surface and registration src/commands/similar.ts, oclif.manifest.json, docs/contract/commands.md, .changeset/first-version.md |
The command and manifest register POST /indexes/{index_uid}/similar and define the available flags. The command contract and changelog describe its usage and body input. |
Request construction and command tests src/commands/similar.ts, test/helpers/meilisearch-handlers.ts, test/commands/similar.test.ts |
The command merges body input with defined flags, with flags taking precedence, calls the endpoint, and outputs its response. Mocked tests cover request parameters, value conversion, output, and errors. |
Meilisearch integration coverage test/integration/meilisearch/similar.test.ts |
Integration tests create an index with an embedder and documents, then cover similar results, filtering, body and flag overrides, and missing-document and missing-index errors. |
Priority:
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Feature
Sequence Diagram(s)
sequenceDiagram
actor Operator
participant SimilarCommand
participant searchSimilarDocuments
participant MeilisearchAPI
Operator->>SimilarCommand: Run with index and options
SimilarCommand->>searchSimilarDocuments: Pass request parameters
searchSimilarDocuments->>MeilisearchAPI: POST /indexes/{index_uid}/similar
MeilisearchAPI-->>searchSimilarDocuments: Return response
searchSimilarDocuments-->>SimilarCommand: Return response
SimilarCommand-->>Operator: Output response
Possibly related PRs
- meilisearch/cli#25: Implements the related document-search command with a similar search-command contract.
- meilisearch/cli#24: Adds the JSON body validation helper used by
meili similarfor--dataand--file.
Merge Risk: 
Minimal · up to 2c22a
-
The similar-documents command is ready to merge after normal checks; no actionable issue was identified.
Pre-merge checks: 
5
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 4 files.
-
Finishing Touches
-
📝 Generate docstrings
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
`search` types its own against `SearchParams`, and #33 types the one of `facet-search` against `Partial<SearchForFacetValuesParams>`, so that a misspelled field fails the typecheck. `SearchSimilarDocumentsParams` has no `retrieveVectors`, which `SimilarQuery` of the OpenAPI document declares, so the same annotation here would cost a documented flag. The comment says it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
What
Add
meili similar, the one route ofPOST /indexes/{index_uid}/similar.Contract
docs/contract/commands.md, and each route is reachable by a distinct set of flags, or the exception is recorded with its reason (or this pull request changes the contract and nothing else)src/lib/output.ts, errors throughsrc/lib/errors.ts$EDITOR; adeletecommand spreadsBaseCommand.confirmFlagsand its examples carry--yesfetchoutsidesrc/lib/clients/Tests
--helpsnapshot added or updated on purposepnpm lint,pnpm typecheck,pnpm testpass locallySimplicity
src/lib/, is used by this command, and is named belowDocs
docs/contract/updated for every name, flag, variable or code this change adds or renames, or nothing to updateHousekeeping
oclif.manifest.jsonregeneratedNotes for the reviewer
No shared code added, no dependency. The command is 103 lines and reuses
connectionFlags,bodyInputFlags,readJsonObjectBodyandasNumber. Both exception rows,POST …/similarand its GET twin, already existed incommands.mdandapi-naming.ts; this pull request only adds the row to the routes table, as #29, #30 and #31 did for theirs.Three things worth a look:
--idis a body field here, not a path parameter. The route takes the index in the path and the document in the body, so--indexis required and--idis not: the exception row already says so, and the contract test accepts it because no route of this command carries a pathid.--idand--embedderare the two fieldsSimilarQuerymarks required, and neither isrequiredin oclif: a whole body can arrive through--dataor--file, and the API names a missing field with its own code, as onmulti-search.The response is hits, so
--output ndjsonis refused, exit 2, likesearch. The envelope also carries theidit was given, which the integration test pins:--data '{"id":1,…}' --id 3answers"id": "3", the flag overriding the body field (rule 8).The integration test configures a
userProvidedembedder and ships the vectors with the three documents, so the suite needs no embedding service and no network: the similarity is the one the fixture wrote. The error case pins the API's ownnot_found_similar_idfor a document that does not exist, exit 1, next to the usualindex_not_found, exit 4.Ran the
simplifyskill on the diff: reuse, simplification and efficiency found nothing. Altitude raised again what #31 already noted — the rule-8 merge block now lives in three command files (search,update settings, here) and its comment had drifted in my first draft, which I fixed by keeping the sibling's wording byte for byte. AmergeJsonObjectBodyinsrc/lib/input.tswould carry it once, but it touches two commands this pull request does not own, so it still belongs in its own change.🤖 Generated with Claude Code
Summary by CodeRabbit