-
Checked other resources
Commit to Help
Example Codeimport { OpenAIEmbeddings } from "@langchain/openai";
import {
DistanceStrategy,
PGVectorStore,
} from "@langchain/community/vectorstores/pgvector";
import { PoolConfig } from "pg";
// First, follow set-up instructions at
// https://js.langchain.com/docs/modules/indexes/vector_stores/integrations/pgvector
const config = {
postgresConnectionOptions: {
type: "postgres",
host: "127.0.0.1",
port: 5433,
user: "myuser",
password: "ChangeMe",
database: "api",
} as PoolConfig,
tableName: "testlangchain",
columns: {
idColumnName: "id",
vectorColumnName: "vector",
contentColumnName: "content",
metadataColumnName: "metadata",
},
// supported distance strategies: cosine (default), innerProduct, or euclidean
distanceStrategy: "cosine" as DistanceStrategy,
};
const pgvectorStore = await PGVectorStore.initialize(
new OpenAIEmbeddings(),
config
);
export {pgvectorStore} DescriptionI'm trying to use PGVector as a retriever but my app keeps crashing with "process is not defined" in console. It isn't listed as "node-only" in the docs, but I'm guessing this isn't the case... System InfoPlatform: Mac |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
The error "process is not defined" suggests that your code, which relies on Node.js-specific features, is being executed in an environment where the Node.js if (typeof process !== "undefined" && process.versions && process.versions.node) {
// Place your Node.js-specific code here
} This snippet checks for the presence of the Regarding PGVector, it is primarily designed for server-side use with PostgreSQL databases, particularly in Node.js environments. Its functionality is centered around supporting efficient vector operations within these databases. While PGVector is not limited to Node.js and can be used in any server-side environment that can connect to PostgreSQL, its direct use in client-side environments like browsers is not feasible without a server-side intermediary to handle database interactions. For your specific case, ensure that your application's architecture correctly distinguishes between server-side and client-side code, especially when dealing with database operations and Node.js-specific features.
|
Beta Was this translation helpful? Give feedback.
-
PGVector uses pg-node to query the DB, so it 's probably Node only. Don't know why it isn't marked as such in the documentation. I'm pretty sure @jacoblee93 has also referenced it being node-only before. For what it's worth, connecting to a DB in the browser isn't something you'd normally want to do. |
Beta Was this translation helpful? Give feedback.
PGVector uses pg-node to query the DB, so it 's probably Node only. Don't know why it isn't marked as such in the documentation. I'm pretty sure @jacoblee93 has also referenced it being node-only before.
For what it's worth, connecting to a DB in the browser isn't something you'd normally want to do.