Przejdź do głównej zawartości

Class: PGVectorStore

Provides support for writing and querying vector data in Postgres. Note: Can't be used with data created using the Python version of the vector store (https://docs.llamaindex.ai/en/stable/examples/vector_stores/postgres.html)

Extends

Implements

Constructors

new PGVectorStore()

new PGVectorStore(config?): PGVectorStore

Constructs a new instance of the PGVectorStore

If the connectionString is not provided the following env variables are used to connect to the DB: PGHOST=your database host PGUSER=your database user PGPASSWORD=your database password PGDATABASE=your database name PGPORT=your database port

Parameters

config?: object & Partial <IEmbedModel>

The configuration settings for the instance.

Returns

PGVectorStore

Overrides

VectorStoreBase . constructor

Source

packages/llamaindex/src/storage/vectorStore/PGVectorStore.ts:52

Properties

collection

private collection: string = ""

Source

packages/llamaindex/src/storage/vectorStore/PGVectorStore.ts:27


connectionString

private connectionString: undefined | string = undefined

Source

packages/llamaindex/src/storage/vectorStore/PGVectorStore.ts:30


db?

private optional db: Client

Source

packages/llamaindex/src/storage/vectorStore/PGVectorStore.ts:33


dimensions

private dimensions: number = 1536

Source

packages/llamaindex/src/storage/vectorStore/PGVectorStore.ts:31


embedModel

embedModel: BaseEmbedding

Inherited from

VectorStoreBase . embedModel

Source

packages/llamaindex/src/storage/vectorStore/types.ts:86


schemaName

private schemaName: string = PGVECTOR_SCHEMA

Source

packages/llamaindex/src/storage/vectorStore/PGVectorStore.ts:28


storesText

storesText: boolean = true

Implementation of

VectorStoreNoEmbedModel . storesText

Source

packages/llamaindex/src/storage/vectorStore/PGVectorStore.ts:25


tableName

private tableName: string = PGVECTOR_TABLE

Source

packages/llamaindex/src/storage/vectorStore/PGVectorStore.ts:29

Methods

add()

add(embeddingResults): Promise<string[]>

Adds vector record(s) to the table. NOTE: Uses the collection property controlled by setCollection/getCollection.

Parameters

embeddingResults: BaseNode <Metadata>[]

The Nodes to be inserted, optionally including metadata tuples.

Returns

Promise<string[]>

A list of zero or more id values for the created records.

Implementation of

VectorStoreNoEmbedModel . add

Source

packages/llamaindex/src/storage/vectorStore/PGVectorStore.ts:196


checkSchema()

private checkSchema(db): Promise<Client>

Parameters

db: Client

Returns

Promise<Client>

Source

packages/llamaindex/src/storage/vectorStore/PGVectorStore.ts:121


clearCollection()

clearCollection(): Promise<QueryResult<any>>

Delete all vector records for the specified collection. NOTE: Uses the collection property controlled by setCollection/getCollection.

Returns

Promise<QueryResult<any>>

The result of the delete query.

Source

packages/llamaindex/src/storage/vectorStore/PGVectorStore.ts:157


client()

client(): Promise<Client>

Connects to the database specified in environment vars. This method also checks and creates the vector extension, the destination table and indexes if not found.

Returns

Promise<Client>

A connection to the database, or the error encountered while connecting/setting up.

Implementation of

VectorStoreNoEmbedModel . client

Source

packages/llamaindex/src/storage/vectorStore/PGVectorStore.ts:148


delete()

delete(refDocId, deleteKwargs?): Promise<void>

Deletes a single record from the database by id. NOTE: Uses the collection property controlled by setCollection/getCollection.

Parameters

refDocId: string

Unique identifier for the record to delete.

deleteKwargs?: any

Required by VectorStore interface. Currently ignored.

Returns

Promise<void>

Promise that resolves if the delete query did not throw an error.

Implementation of

VectorStoreNoEmbedModel . delete

Source

packages/llamaindex/src/storage/vectorStore/PGVectorStore.ts:234


getCollection()

getCollection(): string

Getter for the collection property. Using a collection allows for simple segregation of vector data, e.g. by user, source, or access-level. Leave/set blank to ignore the collection value when querying.

Returns

string

The currently-set collection value. Default is empty string.

Source

packages/llamaindex/src/storage/vectorStore/PGVectorStore.ts:85


getDataToInsert()

private getDataToInsert(embeddingResults): any[][]

Parameters

embeddingResults: BaseNode <Metadata>[]

Returns

any[][]

Source

packages/llamaindex/src/storage/vectorStore/PGVectorStore.ts:167


getDb()

private getDb(): Promise<Client>

Returns

Promise<Client>

Source

packages/llamaindex/src/storage/vectorStore/PGVectorStore.ts:89


persist()

persist(persistPath): Promise<void>

Required by VectorStore interface. Currently ignored.

Parameters

persistPath: string

Returns

Promise<void>

Resolved Promise.

Source

packages/llamaindex/src/storage/vectorStore/PGVectorStore.ts:317


query()

query(query, options?): Promise <VectorStoreQueryResult>

Query the vector store for the closest matching data to the query embeddings

Parameters

query: VectorStoreQuery

The VectorStoreQuery to be used

options?: any

Required by VectorStore interface. Currently ignored.

Returns

Promise <VectorStoreQueryResult>

Zero or more Document instances with data from the vector store.

Implementation of

VectorStoreNoEmbedModel . query

Source

packages/llamaindex/src/storage/vectorStore/PGVectorStore.ts:255


setCollection()

setCollection(coll): void

Setter for the collection property. Using a collection allows for simple segregation of vector data, e.g. by user, source, or access-level. Leave/set blank to ignore the collection value when querying.

Parameters

coll: string

Name for the collection.

Returns

void

Source

packages/llamaindex/src/storage/vectorStore/PGVectorStore.ts:74