Passa al contenuto principale

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)

Implements

Constructors

constructor

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

NameTypeDescription
config?ObjectThe configuration settings for the instance.
config.connectionString?stringThe connection string (optional).
config.dimensions?numberThe dimensions of the embedding model.
config.schemaName?stringThe name of the schema (optional). Defaults to PGVECTOR_SCHEMA.
config.tableName?stringThe name of the table (optional). Defaults to PGVECTOR_TABLE.

Returns

PGVectorStore

Defined in

packages/core/src/storage/vectorStore/PGVectorStore.ts:48

Properties

collection

Private collection: string = ""

Defined in

packages/core/src/storage/vectorStore/PGVectorStore.ts:23


connectionString

Private connectionString: undefined | string = undefined

Defined in

packages/core/src/storage/vectorStore/PGVectorStore.ts:26


db

Private Optional db: Client

Defined in

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


dimensions

Private dimensions: number = 1536

Defined in

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


schemaName

Private schemaName: string = PGVECTOR_SCHEMA

Defined in

packages/core/src/storage/vectorStore/PGVectorStore.ts:24


storesText

storesText: boolean = true

Implementation of

VectorStore.storesText

Defined in

packages/core/src/storage/vectorStore/PGVectorStore.ts:21


tableName

Private tableName: string = PGVECTOR_TABLE

Defined in

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

Methods

add

add(embeddingResults): Promise<string[]>

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

Parameters

NameTypeDescription
embeddingResultsBaseNode<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

VectorStore.add

Defined in

packages/core/src/storage/vectorStore/PGVectorStore.ts:189


checkSchema

checkSchema(db): Promise<Client>

Parameters

NameType
dbClient

Returns

Promise<Client>

Defined in

packages/core/src/storage/vectorStore/PGVectorStore.ts:114


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.

Defined in

packages/core/src/storage/vectorStore/PGVectorStore.ts:150


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

VectorStore.client

Defined in

packages/core/src/storage/vectorStore/PGVectorStore.ts:141


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

NameTypeDescription
refDocIdstringUnique identifier for the record to delete.
deleteKwargs?anyRequired by VectorStore interface. Currently ignored.

Returns

Promise<void>

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

Implementation of

VectorStore.delete

Defined in

packages/core/src/storage/vectorStore/PGVectorStore.ts:227


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.

Defined in

packages/core/src/storage/vectorStore/PGVectorStore.ts:78


getDataToInsert

getDataToInsert(embeddingResults): any[][]

Parameters

NameType
embeddingResultsBaseNode<Metadata>[]

Returns

any[][]

Defined in

packages/core/src/storage/vectorStore/PGVectorStore.ts:160


getDb

getDb(): Promise<Client>

Returns

Promise<Client>

Defined in

packages/core/src/storage/vectorStore/PGVectorStore.ts:82


persist

persist(persistPath, fs?): Promise<void>

Required by VectorStore interface. Currently ignored.

Parameters

NameType
persistPathstring
fs?GenericFileSystem

Returns

Promise<void>

Resolved Promise.

Defined in

packages/core/src/storage/vectorStore/PGVectorStore.ts:310


query

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

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

Parameters

NameTypeDescription
queryVectorStoreQueryThe VectorStoreQuery to be used
options?anyRequired by VectorStore interface. Currently ignored.

Returns

Promise<VectorStoreQueryResult>

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

Implementation of

VectorStore.query

Defined in

packages/core/src/storage/vectorStore/PGVectorStore.ts:248


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

NameTypeDescription
collstringName for the collection.

Returns

void

Defined in

packages/core/src/storage/vectorStore/PGVectorStore.ts:67