Giter Club home page Giter Club logo

Comments (7)

louis030195 avatar louis030195 commented on May 24, 2024

PS: need to improve error handling when using embedbase-js sdk at some level to determine

from embedbase.

louis030195 avatar louis030195 commented on May 24, 2024

need to try dot product instead of cos sim in pgvector:

...
  select
    STUFFHERE,
    (documents.embedding <#> embedding) * -1 as similarity
  from documents

  -- The dot product is negative because of a Postgres limitation, so we negate it
  and (documents.embedding <#> embedding) * -1 > match_threshold

  -- OpenAI embeddings are normalized to length 1, so
  -- cosine similarity and dot product will produce the same results.
  -- Using dot product which can be computed slightly faster.
  --
  -- For the different syntaxes, see https://github.com/pgvector/pgvector
  order by documents.embedding <#> embedding
  
  limit match_count;
end;
$$;

need to setup performance monitoring beforehand though

from embedbase.

louis030195 avatar louis030195 commented on May 24, 2024

pgvector/pgvector#82

from embedbase.

louis030195 avatar louis030195 commented on May 24, 2024

different thing that could be tried that will highly likely improve perf:

  1. image
  2. https://github.com/pgvector/pgvector#query-options
  3. increase list size (because table starts growing beyond the optimal 100) CREATE INDEX ON items USING ivfflat (embedding vector_ip_ops) WITH (lists = 220);
  4. use SCANN/FAISS + Supabase

from embedbase.

louis030195 avatar louis030195 commented on May 24, 2024

To update the index to use 220 lists, you'll need to first drop the existing index and then create a new index with the desired lists value. Here are the SQL commands to do that:

-- Drop the existing index
DROP INDEX documents_embedding_vector_cosine_ops_idx;

-- Create a new index with 220 lists
CREATE INDEX documents_embedding_vector_cosine_ops_idx
ON documents
USING ivfflat (embedding vector_cosine_ops)
WITH (lists = 220);

Replace documents_embedding_vector_cosine_ops_idx with the actual name of your index if it's different.

Dropping and recreating an index can have some impact on your users, depending on your database's current usage and workload. Here's how it might affect your users:

  1. Query performance: While the index is being dropped and recreated, any queries that rely on this index may experience slower performance because the database will need to do a full table scan instead of using the index.

  2. Table lock: Depending on the PostgreSQL version and configuration, dropping and creating an index might lock the table or cause other queries to be blocked. This can cause delays for users trying to access the table during the index operation.

To minimize the impact on your users, consider performing the index update during a maintenance window or a period of low database usage. Additionally, you can use the CONCURRENTLY keyword when creating the new index to avoid locking the table:

-- Create a new index with 220 lists, concurrently
CREATE INDEX CONCURRENTLY documents_embedding_vector_cosine_ops_idx
ON documents
USING ivfflat (embedding vector_cosine_ops)
WITH (lists = 220);

Note that you cannot use the CONCURRENTLY keyword when dropping an index. However, dropping an index is generally a quick operation and should not cause significant disruption.

from embedbase.

louis030195 avatar louis030195 commented on May 24, 2024

nvm all this. just need to distinct the select query when optimizing duplicates

from embedbase.

louis030195 avatar louis030195 commented on May 24, 2024

fixed 🚢🚢🚢🚢🚢

from embedbase.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.