Module: Parse::Core::VectorSearchable
- Included in:
- Object
- Defined in:
- lib/parse/model/core/vector_searchable.rb
Overview
Class-level ‘find_similar` wrapper around VectorSearch.search for any Parse::Object subclass that has declared at least one `:vector` property.
The wrapper handles three things the low-level entry point doesn’t:
-
**Field resolution.** Defaults to the subclass’s single ‘:vector` property; raises if the class has none, requires explicit `field:` if it has more than one.
-
**Declared-dimension validation.** Compares the query vector’s length against the ‘dimensions:` declared on the property, so callers get “expected 1536, got 768” instead of an Atlas- side error after a round-trip.
-
**Index auto-discovery.** Looks up the Atlas vectorSearch index covering the field via AtlasSearch::IndexManager.find_vector_index when no explicit ‘index:` kwarg is given.
ACL/CLP enforcement is inherited from VectorSearch.search (which routes through MongoDB — REST ‘/aggregate` is master-key-only and bypasses ACL/CLP, see CLAUDE.md). The full scope-kwarg surface (`session_token:`, `master:`, `acl_user:`, `acl_role:`) is forwarded as-is.
Defined Under Namespace
Classes: AmbiguousVectorField, EmbedderNotConfigured, IndexNotResolved, NoVectorProperty
Instance Method Summary collapse
-
#find_similar(vector: nil, text: nil, k: 10, field: nil, filter: nil, vector_filter: nil, index: nil, num_candidates: nil, max_time_ms: nil, raw: false, **scope_opts) ⇒ Array<Parse::Object>, Array<Hash>
Find documents whose declared ‘:vector` property is closest to `vector:` under the Atlas vectorSearch index’s similarity function.
Instance Method Details
#find_similar(vector: nil, text: nil, k: 10, field: nil, filter: nil, vector_filter: nil, index: nil, num_candidates: nil, max_time_ms: nil, raw: false, **scope_opts) ⇒ Array<Parse::Object>, Array<Hash>
When ‘text:` is given, the text is sent over the wire to the embedding provider (e.g. OpenAI). Operators that enable global Faraday request logging on the embedding connection will capture the full query text in the JSON request body. Treat `text:` as user-visible content for log-handling purposes.
The provider is responsible for bounding its own request timeout. Embeddings::OpenAI self-bounds at 30 s read / 5 s connect with capped retries. Custom providers MUST self-bound — ‘find_similar` does not impose a wall-clock deadline on the embed step.
Find documents whose declared ‘:vector` property is closest to `vector:` under the Atlas vectorSearch index’s similarity function.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/parse/model/core/vector_searchable.rb', line 129 def find_similar(vector: nil, text: nil, k: 10, field: nil, filter: nil, vector_filter: nil, index: nil, num_candidates: nil, max_time_ms: nil, raw: false, **scope_opts) if vector.nil? && text.nil? raise ArgumentError, "#{self}.find_similar: must pass either `vector:` or `text:`." end if !vector.nil? && !text.nil? raise ArgumentError, "#{self}.find_similar: pass either `vector:` or `text:`, not both." end resolved_field = resolve_vector_field!(field) declared_dims = vector_properties.dig(resolved_field, :dimensions) query_vector = if text.nil? coerce_query_vector(vector) else (text, resolved_field) end Parse::VectorSearch.validate_query_vector!(query_vector, dimensions: declared_dims) index_name = resolve_vector_index!(resolved_field, index) raw_hits = Parse::VectorSearch.search( parse_class, field: resolved_field, query_vector: query_vector, k: k, num_candidates: num_candidates, filter: filter, vector_filter: vector_filter, index: index_name, max_time_ms: max_time_ms, **scope_opts, ) return raw_hits if raw build_vector_hits(raw_hits) end |