Build a personal knowledge base based on Quivr

Table of contents

Introduction to Quivr

Quivr features

Quivr Demo

        Demo with GPT3.5:

        Demo of the new version:

Quivr in action

The main technologies used by Quiv

Quiv Practice Depends

Create a Supabase project

Deploy the Quiv project

        The first step: now the source code

        Step 2: Set environment variables

        The third step: execute sql

        Step 4: Launch the application

        Step 5: Effect Demonstration

                user login:

                Upload knowledge base:

                 Modify the Q&A prompt for Q&A


        Today we try to use the open source framework Quivr to build our own knowledge base. The official website bills Quivr as your second brain, harnessing the power of generative artificial intelligence to store and retrieve unstructured information. You can think of it like Obsidian with AI capabilities. Looking at the introduction pattern on the official website, there is also a tree of wisdom growing out of obsidian, and the implication is really awesome.

Introduction to Quivr

        Quivr uses advanced artificial intelligence technology to help you generate and retrieve information, and can handle almost all types of data, including text, images, code snippets, etc. At the same time, it also focuses on speed and efficiency, ensuring that data can be accessed quickly. Data security is under your control. Quivr supports multiple file formats, including text, Markdown, PDF, PowerPoint, Excel, Word, audio, video, etc.

Quivr features

  •  Universal Data Acceptance: Quivr can handle almost any type of data you throw at it. Including text, Markdown, PDF, PowerPoint, Excel, Word, audio, video, and more.
  • Generative AI: Quivr uses advanced artificial intelligence to help you generate and retrieve information.
  • Fast and Efficient: Because it was designed with speed and efficiency at its core, Quivr ensures fast access to data.
  • Secure: In any scenario and at any time, your data is under your control.
  • Open Source: open source, free of charge.

Quivr Demo

Demo with GPT3.5:

        The following video is a demo demonstration based on ChatGPT3.5, which demonstrates the construction of a knowledge base and multiple rounds of dialogue question and answer. https://user-images.githubusercontent.com/19614572/238774100-80721777-2313-468f-b75e-09379f694653.mp4

Demo of the new version:

        The following video is a demonstration video of the latest version launched in late May. The new version replaces the operation UI. Next, we try to use the new version to build our own knowledge base. https://user-images.githubusercontent.com/19614572/239713902-a6463b73-76c7-4bc0-978d-70562dca71f5.mp4

Quivr in action

The main technologies used by Quiv

        Quivr, like other knowledge base solutions, is essentially based on the interaction between prompts and large models. The main technologies used by Quivr are:

  • LLM:GPT3.5 / GPT 4
  • Embedding:OpenAI embedding
  • Vector knowledge base: Supabase
  • Docker:Docker Compose

Quiv Practice Depends

        We have mentioned earlier that Quivr uses the Supabase vector database, so before that we need to create a Supabase account, obtain the Supabase Project API key, Supabase Project URL, and generate several necessary tables.

Create a Supabase project

        Supabase's official website address is: Dashboard | Supabase If you have a github account, you can log in directly with your GitHub account. If you don't have one, you can register in other ways. It is relatively simple to create a project. There are paid and free ones when creating it. Let's practice direct prostitution and choose the free method decisively. After the project is created, the relevant configuration of the project will appear. What we need is the one marked in the second picture. If you want to find these information again later, you can use this address: API Settings | Supabase, or select the project to enter the settings Inquire.

Deploy the Quiv project

        After the pre-environment is ready, we start to deploy the Quiv project.

The first step: now the source code

        

git clone https://github.com/StanGirard/quivr.git && cd quivr 
# 切换到 v0.0.4分支 
git checkout v0.0.4 
git checkout -b v0.0.4

Step 2: Set environment variables

        You need to modify the environment variables in the frontend and backend directories, copy them here first. The picture below is my local replacement according to the configuration in the created project. It should be noted that the ANTHROPIC_API_KEY in the backend directory is the configuration of Claude, we can delete it.

cp .backend_env.example backend/.env 
cp .frontend_env.example frontend/.env

The third step: execute sql

        After the configuration is complete, the next step is to initialize the database. Open the Supabase panel, click to create a sql execution box as shown in the figure below, and execute the following sql codes in sequence.

create extension vector;

-- Create a table to store your documents
create table if not exists documents (
id bigserial primary key,
content text, -- corresponds to Document.pageContent
metadata jsonb, -- corresponds to Document.metadata
embedding vector(1536) -- 1536 works for OpenAI embeddings, change if needed
);

CREATE FUNCTION match_documents(query_embedding vector(1536), match_count int)
    RETURNS TABLE(
        id bigint,
        content text,
        metadata jsonb,
        -- we return matched vectors to enable maximal marginal relevance searches
        embedding vector(1536),
        similarity float)
    LANGUAGE plpgsql
    AS $$
    # variable_conflict use_column
BEGIN
    RETURN query
    SELECT
        id,
        content,
        metadata,
        embedding,
        1 -(documents.embedding <=> query_embedding) AS similarity
    FROM
        documents
    ORDER BY
        documents.embedding <=> query_embedding
    LIMIT match_count;
END;
$$;
create table
  stats (
    -- A column called "time" with data type "timestamp"
    time timestamp,
    -- A column called "details" with data type "text"
    chat boolean,
    embedding boolean,
    details text,
    metadata jsonb,
    -- An "integer" primary key column called "id" that is generated always as identity
    id integer primary key generated always as identity
  );
-- Create a table to store your summaries
create table if not exists summaries (
    id bigserial primary key,
    document_id bigint references documents(id),
    content text, -- corresponds to the summarized content
    metadata jsonb, -- corresponds to Document.metadata
    embedding vector(1536) -- 1536 works for OpenAI embeddings, change if needed
);

CREATE OR REPLACE FUNCTION match_summaries(query_embedding vector(1536), match_count int, match_threshold float)
    RETURNS TABLE(
        id bigint,
        document_id bigint,
        content text,
        metadata jsonb,
        -- we return matched vectors to enable maximal marginal relevance searches
        embedding vector(1536),
        similarity float)
    LANGUAGE plpgsql
    AS $$
    # variable_conflict use_column
BEGIN
    RETURN query
    SELECT
        id,
        document_id,
        content,
        metadata,
        embedding,
        1 -(summaries.embedding <=> query_embedding) AS similarity
    FROM
        summaries
    WHERE 1 - (summaries.embedding <=> query_embedding) > match_threshold
    ORDER BY
        summaries.embedding <=> query_embedding
    LIMIT match_count;
END;
$$;

Step 4: Launch the application

        The preparatory work in the previous steps is done, and now you can start the application. It should be noted that if the version of docker is too low, an error will be prompted and docker needs to be updated. Everyone can update to the version according to their own timing. This step takes a long time to start because the image needs to be packaged and the application started.

docker compose build && docker compose up

Step 5: Effect Demonstration

user login:

Upload knowledge base:

 Modify the Q&A prompt for Q&A

        Next, you can perform questions and answers on the knowledge base. At present, the source code still supports English questions and answers. If we want to use Chinese, we can modify the question and answer template. , hahaha), the file path is as follows:

Guess you like

Origin blog.csdn.net/lly576403061/article/details/131145522