Cosine and internal search: whether or not the vector length is involved in sorting

The internal build-up is influenced by both direction and length, and cosine similarities are unicoded and mainly compared in direction.

Thematic shorts • IntroductionCollate in 1 diagram2 self-measured2 First-hand sources
Start Body
Learning objectives and first steps2 objectives . 1 first fix

Try to do it after reading

  • Explain cosine and inner volume search: mechanisms and prerequisites for whether vector lengths are involved in sorting
  • Positioning the mechanism ' s fault limits with fixed examples

Suggested first

  • vector coefficients and points

Issues and mechanisms

The internal build-up is influenced by both direction and length, and cosine similarities are unicoded and mainly compared in direction. (a) Which targets are used in the search model training, which affects the most appropriate similarities; You can't switch at will for values to look familiar. Whether the vector has been normalized also needs to be checked for real output rather than extrapolated by model names.

For non-zero vectors, cosine is equal to the internal division of the two-sided coefficients multiplied. If all document vectors are unitized with queries, the inner volume and cosine are sorted in the same order; If the document is of different lengths, the result can be reversed. Zero vectors are not defined as normal cosine and require explicit rejection or regression. The type of distance used for approximation of the index must also be aligned with the offline rehearsing, avoiding the recall phase having adopted another goal.

cos(q,d)=q⊤d∥q∥∥d∥

A concrete example

Synthetic query q = [10], candidate A = [2,0], B = [10,10]. 2 and 10 respectively, preferred B; Cosine 1 and about 0.707, respectively, preferred A. Groups the cosine by uniting the two documents and then building them in. This counter-examples that vector length may carry model training information or may be irrelevant and based on formula and validation options.

The direction and length of the same candidateQueries, A, B XV; Cosine preference A, original inner balance preference B. Only cosine values are drawn here.A cosine1 SimilarityB cosine0.707107 Similarity
Queries, A, B XV; Cosine preference A, original inner balance preference B. Only cosine values are drawn here.

Borders and checks

A small batch of primary vectors should be kept for verification, checking the pattern distributions, similarities and consistency with index returns. If the deployment end is automatically normalized and the training end is not available, the change in quality should be considered a change in the agreement.

The same numerical distance does not cross the model to indicate a generic meaning, and the compatible index should be recreated in the embedding version. There may also be differences in the language, length and field, and it is not possible to apply a single English short sentence to the full collection of papers.

A method of verification

You can also multiply all document vectors by the same positive number, confirming that the pure cosine result remains unchanged; A document is only magnified to change its internal build without changing its cosine. This test shows whether the service end is being diluted. The smaller the distance, the better, should also be checked, especially when the index returns the distance and the sorter expects a similarity, and the misdirection of the symbol still makes it possible to output the full list. Saves several hand-count vectors as a sample of long-term regression after model and index upgrades.

Check understanding

Does the inner and cosine order on the unit vector differ?

(b) The same as under the exact calculation and the same vector, since the denominator is one; Approximately indexing and numerical accuracy may be different.

Can the cosine of the zero vector be set to one automatically?

There is no such mathematical basis. An anomaly should be dealt with under the interface contract, and the absence cannot be expressed as a complete similarity, otherwise the contamination candidate would be.

Sources and reconciliations

Definitions, methods and interfaces are available.

  1. Dense Passage Retrieval
  2. BEIR — A Heterogenous Benchmark for Zero-shot Evaluation of Information Retrieval Models

Figures and calculations are reorganized according to this chapter. Mathematical measurements, framework operations and real business effects are described separately in the body of the text.

← Back to the knowledge directory
Ask Max Ask about this site
Ask Max ↗

Opening the assistant…

Paper figure

Photo comments

LEAVE A NOTE

About this photograph

Connecting to the discussion board…

    Comments become public after moderation. You can delete your own comments from this browser.
    No email is required. Clearing cookies prevents this browser from claiming earlier comments.

    MAX WANG / INDEX

    Find something

    Enter a keyword, or explore the directory below.