LangChain Indexing API - Update your Embeddings SURGICALLY!

Coding Crashcourses
11 Sept 202307:13

Summary

TLDRこの動画は、リンクチェーンインデックスAPIの紹介とその大きなアップデートについて説明しています。このAPIは、ドキュメントの変更を追跡し、変更されたドキュメントだけを更新することで、インデックスを再作成するコストを削減することができます。また、データベースのアップデート方法や、PGベクターの使い方、そしてドキュメントの追跡と削除についても詳細に説明されています。このAPIの利用は、大規模なアプリケーションを構築する際に特に重要です。

Takeaways

  • 🔗 リンクチェーンインデックスAPIの紹介: 大規模なアプリケーションにとって非常に重要なアップデートです。
  • 📄 現在のワークフロー: ドキュメントを作成し、ベクトルストアに埋め込みを保存します。
  • 🔄 データの更新がある場合: 古いインデックスを破棄し、新しい埋め込みを作成します。
  • 🚀 インデックスAPIの利点: ドキュメントの変更を追跡し、変更されたドキュメントだけを更新することができます。
  • 🐳 Dockerを使用してベクトルストアをホストし、Postgresデータベースを利用しています。
  • 📦 PG Vector拡張機能をダウンロードして、init SQLスクリプトで作成します。
  • 🛠️ コードデモ: Docker Composeを使用してベクトルストアを作成し、インデックスAPIを操作します。
  • 📄 ドキュメントの作成: 'bellavista.txt'を読み込んで、テキストローダーとテキストスプリッターを使用します。
  • 🔄 ドキュメントの更新と削除: クリーンアップ方法を使用して、ベクトルストア内のドキュメントを管理します。
  • 🗑️ クリーンアップ方法: 'none'でスキップ、「incremental」で更新と削除、「full」で全てのドキュメントを再確認します。
  • 🎯 アプリケーションのスケールアップやベクトルストアの管理に重要な役割を果たすインデックスAPIのアップデートについて学びました。

Q & A

  • Link ChainのインデックスAPIとは何ですか?

    -Link ChainのインデックスAPIは、ドキュメントの変更を追跡し、変更されたドキュメントだけを更新する機能です。これにより、インデックスを一旦捨てて再作成する必要がなくなります。

  • ベクトルストアとは何ですか?

    -ベクトルストアは、ドキュメントから生成されたベクトルを保存するためのデータベースです。これにより、類似性検索や情報検索などのタスクを効率的に行うことができます。

  • PG Vectorとは何ですか?

    -PG Vectorは、PostgreSQLデータベースにベクトル検索機能を提供するオープンソースの拡張機能です。ベクトルデータを効率的に管理し、類似性検索を可能にします。

  • インデックスAPIを使用するメリットは何ですか?

    -インデックスAPIを使用することで、ドキュメントの更新や削除を効率的に追跡し、無駄な処理やコストを削減することができます。また、大規模なアプリケーションの開発にも役立ちます。

  • どのようにしてベクトルストアを初期化しますか?

    -ベクトルストアを初期化するには、Docker-composeを使用してPostgreSQLデータベースをホストし、PG Vector拡張機能をインストールします。その後、init SQLスクリプトでベクトルストアを作成します。

  • ドキュメントをどのように分割しますか?

    -ドキュメントは、テキスト分割器(例:CharacterTextSplitter)を使用して分割されます。これにより、各分割された部分を個別のドキュメントとして扱うことができます。

  • SQLレコードマネージャーとは何ですか?

    -SQLレコードマネージャーは、ドキュメントを追跡するためのデータベースオブジェクトです。これにより、PG Vectorと組み合わせて使用することで、複数のデータベースを作成せずにドキュメントを管理できます。

  • cleanupオプションは何を制御しますか?

    -cleanupオプションは、ドキュメントの更新や削除時にベクトルストア内のベクトルの削除を制御します。'incremental'では変更されたドキュメントだけが削除されますが、'full'ではすべてのドキュメントがリストに含まれている必要があります。

  • ドキュメントの変更を追跡する方法は何ですか?

    -ドキュメントの変更を追跡する方法は、Source IDキーを使用して行います。このキーはメタデータ属性に含まれており、インデックス関数で参照されます。これにより、ドキュメントの変更や削除がベクトルストアに反映されます。

  • インデックスAPIを使用する際に、どのような種類のデータベースが使用できますか?

    -インデックスAPIを使用する際には、SQLベースのデータベースを使用することができます。このため、PostgreSQLなどのデータベースを使用して、ドキュメントの追跡や管理を効率的に行うことができます。

  • ベクトルストアとインデックスAPIを組み合わせて使用する利点は何ですか?

    -ベクトルストアとインデックスAPIを組み合わせて使用することで、ドキュメントの変更をリアルタイムで追跡し、更新されたベクトルのみを再計算することができます。これにより、処理時間とコストを大幅に削減し、アプリケーションのスケーラビリティを向上させることができます。

Outlines

00:00

🔗 リンクチェーンインデックスAPIの紹介

この段落では、リンクチェーンインデックスAPIの導入とその大きなアップデートについて説明されています。現在のワークフローでは、ドキュメントがVectorストアに作成、埋め込み、保存されています。生のデータが更新されると、インデックスを捨てて新しい埋め込みを作成します。 インデックスAPIは、変更されたドキュメントだけを追跡・更新することで、無駄な費用を削減できる機能です。コードを通じてこのAPIの使い方を見直し、Docker-composeを使用してVectorストアを作成し、PG Vector拡張を利用しています。 また、ドキュメントの追跡や埋め込みの方法についても詳細に説明されています。

05:02

📄 ドキュメントの更新とクリーンアップ

この段落では、ドキュメントの更新とクリーンアップのプロセスについて説明されています。まず、新しいドキュメントを作成し、既存のドキュメントを削除して更新します。クリーンアップ機能は、変更されていないドキュメントをスキップし、変更されたものや新たに追加されたもののみを扱います。 クリーンアップ方法には、'incremental'と'full'の2つのオプションがあります。'incremental'は、大きなデータセットに適しており、変更された部分のみをアップデートします。'full'は、全てのドキュメントを再アップデートするため、小規模なデータセットに適しています。 また、空のリストを提供することで、Vectorストアから全てのドキュメントを削除する方法も紹介されています。

Mindmap

Keywords

💡link chain indexing API

このAPIは、ドキュメントの変更を効率的に追跡し、インデックスを更新する際に不要なドキュメントを削除したり、新しい埋め込みを追加したりする機能を提供します。ビデオの主題である大規模なアプリケーション作成において、このAPIは非常に重要です。

💡Vector stores

ベクターストアは、ドキュメントを保存し、それらのベクター嵌入を作成し、検索や機械学習タスクで使用するためのデータ構造です。ビデオでは、ベクターストアを使用して、ドキュメントを保存し、更新された場合にのみ再処理する方法が説明されています。

💡embeddings

埋め込みは、高次元空間に存在するデータ点を低次元の連続ベクトルに変換するプロセスです。これにより、コンピュータが数字データをより効果的に処理できるようになります。ビデオでは、ドキュメントのテキストを埋め込みとして保存し、検索や分類タスクで使用する方法が説明されています。

💡PG Vector

PG Vectorは、PostgreSQLデータベースに組み込まれた拡張機能で、ベクター嵌入を効率的に管理、検索、更新することができます。ビデオでは、PG Vectorを使用して、ベクターストアをホストし、ドキュメントの変更を追跡する方法が説明されています。

💡record manager

レコードマネージャーは、データベース内のドキュメントを追跡し管理するためのソフトウェアコンポーネントです。ビデオでは、SQLレコードマネージャーを使用して、ベクトルストア内のドキュメントを追跡し、変更を効率的に更新する方法が説明されています。

💡metadata

メタデータは、データに関する情報です。これには、データの構造、形式、内容についての情報が含まれます。ビデオでは、ドキュメントのメタデータを使用して、ベクトルストア内のドキュメントを識別し、追跡する方法が説明されています。

💡cleanup

クリーンアップは、不要なデータやファイルを削除し、システムを効率的かつ整理された状態に保つプロセスです。ビデオでは、ベクトルストア内の古くなったベクトルを削除し、最新の情報を維持する方法が説明されています。

💡incremental

インクリメンタルは、システムの変更を徐々に適用し、一度に全てを更新するのではなく、変更が発生した部分だけを更新するプロセスです。ビデオでは、インクリメンタルクリーンアップを使用して、ベクトルストア内の変更されたドキュメントだけを更新する方法が説明されています。

💡full

フルは、システム内の全てのデータやファイルを一度に更新または削除するプロセスです。ビデオでは、フルクリーンアップを使用して、ベクトルストア内の全てのドキュメントを削除し、新しい状態から始めることもできます。

💡Docker

Dockerは、ソフトウェアアプリケーションをパッケージ化し、実行するためのオープンソースプラットフォームです。ビデオでは、Dockerを使用してPG Vector拡張機能をインストールし、ベクトルストアをホストする方法が説明されています。

💡SQL

SQLは、関係型データベースで使用される標準的な問い合わせ言語です。ビデオでは、SQLを使用して、ベクトルストア内のドキュメントを管理し、更新する方法が説明されています。

Highlights

Introduction to the link chain indexing API, a significant update for real-world applications.

Current workflow with Vector stores involves creating embeddings and storing documents, which can be costly if raw data frequently updates.

The indexing API allows tracking of documents and updating only changed documents, avoiding recreating the index or having outdated vectors.

Demonstration of using code to work with the indexing API, including setting up a Vector store and using Docker and a Postgres database.

Using Docker Compose to create and host the Vector store, with the postgres database file detailing the setup and installation of the PG Vector extension.

Explanation of the SQL record manager, which is essential for creating embeddings and storing documents in the Vector store, and its compatibility with PG Vector.

Process of creating a new Vector store collection by setting up a connection string and collection name, and the importance of the 'docs' parameter.

Loading and processing a text file (bellavista.txt) into multiple documents using the text loader and character text splitter.

Utilization of the document class with its 'page content' property and 'metadata' attribute, which is crucial for linking documents to their embeddings in the Vector store.

Explanation of the 'index' function, its parameters, and the 'clean' setup option, which determines how the API handles existing and new documents.

Demonstration of adding documents to the Vector store, noting that re-running the process does not add new documents if they already exist, thus saving resources.

Discussion on the 'cleanup' method, including 'none', 'incremental', and 'full' options, and their impact on document and vector management in the Vector store.

Example of updating and deleting documents and how the indexing API reflects these changes in the Vector store, ensuring the store remains up-to-date.

The 'full' cleanup method's role in treating the document list as the entire universe of documents, suitable for small datasets but not for larger ones.

Use of the 'cleanup' method with an empty list to delete all documents from the Vector store, a potential strategy for resetting the store.

The indexing API's importance for creating larger scale applications and its impact on the efficiency and cost-effectiveness of managing Vector stores.

Conclusion and appreciation for the audience, emphasizing the value of the new update and its significance for link chain applications.

Transcripts

play00:00

hi everybody today I want to introduce

play00:02

you to the link chain indexing API this

play00:04

update is quite huge and very important

play00:06

for real-world applications to

play00:08

understand the benefits we have to take

play00:10

a look at the current workflow with

play00:11

Vector stores you have your documents

play00:13

create your embeddings and store

play00:14

everything in the vector store if the

play00:16

raw data gets updated you dump the index

play00:18

and create new embeddings if you've got

play00:20

a lot of documents or frequently have to

play00:22

update your documents for example if you

play00:24

index data from a News website this may

play00:26

get quite expensive the indexing API

play00:29

lets you keep track of the documents and

play00:31

only update the change documents without

play00:33

dropping or recreating an index or if

play00:36

you wouldn't drop the index having

play00:37

outdated vectors in your store let's now

play00:39

have a look at how this works with code

play00:41

and as always you can follow along by

play00:43

cloning the repository link is in the

play00:45

description okay as you can see I'm in

play00:47

vs code and this is the repository we've

play00:50

got multiple files here the docker

play00:52

compose yaml is responsible for creating

play00:54

and hosting our Vector store we use the

play00:56

postgres database here is the docker

play00:58

file we inherit from postgres and

play01:00

installed some packages here we download

play01:02

the PG Vector extension and then create

play01:05

the extension in that init SQL script so

play01:08

we create the extension Vector here so

play01:11

that's then the vector store and in the

play01:14

code iPad notebook we've got the code to

play01:17

work with the indexing API okay to make

play01:20

that work we first have to run Docker

play01:22

minus compose up

play01:24

and then the vector store will be

play01:27

downloaded and created and now we can

play01:30

create our Vector store collection so we

play01:34

set up our

play01:35

connection string we set up the

play01:37

collection name and then we create the

play01:40

vector store here we pass in as docs

play01:42

just an empty list because we won't

play01:44

store any documents with this PG Vector

play01:47

from documents method but we will use

play01:49

the record manager to do so so we run

play01:52

that

play01:53

and then we've got our new Vector store

play01:56

so okay let's first create some

play01:58

documents and I will load this

play02:01

bellavista.txt this is just a little q a

play02:04

for a fictional restaurant here we can

play02:06

see the question and the answers and we

play02:09

will load that with the text loader and

play02:12

then split it into multiple documents

play02:14

with the character text splitter so if

play02:16

we run this we can see we create our

play02:19

chunks and we want to store that chunks

play02:22

as embeddings in our store you can see

play02:24

we've got seven documents so first we

play02:26

have to import the SQL record manager

play02:30

this is currently the only record

play02:31

manager so we have to use a SQL database

play02:34

for creating our record manager which

play02:37

keeps track of the documents so this

play02:40

works very well in combination with PG

play02:42

Vector because you don't have to create

play02:44

multiple databases okay now we have to

play02:47

set up the record manager and we have to

play02:49

pass in a namespace argument this is

play02:52

just a string and we pass in here the

play02:54

collection name from the vector database

play02:56

and very important here we have to pass

play02:59

in a connection string so since this is

play03:00

PG Vector we can use the same connection

play03:03

string as for the vector store so

play03:05

nothing new will be created here

play03:09

let's run this

play03:12

of course we first have to import it

play03:15

no let's run it

play03:17

okay now we can run the create schema

play03:20

method and this will set up our table

play03:23

okay

play03:25

so let's load the data here again

play03:28

and we'll just take a look at it as you

play03:30

can see we've got seven chunks again and

play03:33

this makes use of the document class the

play03:36

document class has got a page content

play03:38

property and also we have to scroll a

play03:41

little bit here

play03:42

has got this meta data attribute so in

play03:46

the metadata attribute we've got a

play03:49

dictionary and in the dictionary we can

play03:51

set up keys so link chain will

play03:53

automatically set up this Source key and

play03:56

we have to reference that Source key

play03:58

in the index function so we pass the

play04:02

docs to the index function we pass the

play04:04

record manager and the vector store

play04:05

setup is currently set to clean I will

play04:08

explain in a few seconds what this means

play04:11

and also we set this Source ID key so

play04:14

there's a source because in the metadata

play04:16

we have got this Source key so this will

play04:19

be hashed now and now keep track of

play04:22

changes in the documents so if you run

play04:25

this here we can see that we added seven

play04:28

documents to the vector store if we run

play04:31

it again we can see that now we have

play04:34

zero documents added this because in the

play04:38

first run we created the documents once

play04:40

and in the second run it identified that

play04:43

the documents are already present in the

play04:45

vector store so it didn't create new

play04:47

embeddings and we saved some money here

play04:50

okay now we've got this cleanup set to

play04:53

none but what does this actually do I

play04:56

will show you in the example I provide

play04:58

you here and we create a new document so

play05:02

first we update the first document we

play05:04

will delete the document and we will

play05:06

also append a new document

play05:09

so now we've got an updated documents

play05:12

list and if we run it again also with

play05:15

cleanup none then we can see the

play05:17

following we can see that five documents

play05:20

were skipped and two documents were

play05:23

added so despite we deleted the raw

play05:26

documents they did not get deleted in

play05:28

the vector store so this is now a little

play05:30

bit out of sync but this can be

play05:32

intentional if you want to keep track of

play05:35

your old vectors but I think it's better

play05:36

to use the cleanup incremental method

play05:40

here so if you run that again we already

play05:42

added these documents here so we can

play05:45

just

play05:46

see that we will delete this so we will

play05:49

delete two documents and this is because

play05:51

this was updated so we delete the old

play05:54

vector and this was completely deleted

play05:56

from the documents so this gets also

play05:58

deleted from the vector store so every

play06:00

time we update or delete the document

play06:02

the vector will be deleted as well for

play06:06

the cleanup method there is another

play06:07

argument we can set and this is full so

play06:10

the difference between incremental and

play06:12

fullest that full expects this list of

play06:16

documents to be the whole universe of

play06:19

documents you want to store in your

play06:20

vector database this can be comfortable

play06:22

if you've got a small number of

play06:25

documents but it's not very helpful if

play06:28

you've got a large number of documents

play06:29

because you don't want to store all of

play06:32

your documents in memory so if you've

play06:35

got large number of documents use

play06:36

incremental if you've got small and

play06:39

often changing documents then use full

play06:42

if you want to clean up I will show you

play06:43

what this does when you provide an empty

play06:45

list so this will actually

play06:47

delete every document in the vector

play06:49

store so now we've got an empty Vector

play06:52

store so this can be a little bit of

play06:54

hack to actually drop all of your

play06:57

vectors from the vector store so that's

play06:59

it for the video I think that new update

play07:01

the indexing API is a quite important

play07:04

update for link chain especially if you

play07:05

want to create larger scale applications

play07:08

okay thank you very much for watching

play07:10

please like the video and subscribe to

play07:11

my channel see you bye bye

Rate This

5.0 / 5 (0 votes)

Related Tags
LinkChainインデックスAPIドキュメント管理効率化アップデートベクトルストアSQLデータベース技術紹介チュートリアルPGVector
Do you need a summary in English?