How to do indexing using postgres #29269
Replies: 1 comment 20 replies
-
To perform indexing using PostgreSQL with the PGVector library in Python, you can use the Here's a basic example of how to set up and use PGVector for indexing: from langchain_community.vectorstores import PGVector
from langchain_community.embeddings.openai import OpenAIEmbeddings
# Define your connection string
CONNECTION_STRING = "postgresql+psycopg2://username:password@localhost:5432/your_database"
# Define your collection name
COLLECTION_NAME = "your_collection_name"
# Initialize your embeddings
embeddings = OpenAIEmbeddings()
# Create a PGVector instance from documents
vectorestore = PGVector.from_documents(
embedding=embeddings,
documents=docs, # Replace with your list of documents
collection_name=COLLECTION_NAME,
connection_string=CONNECTION_STRING,
use_jsonb=True, # Use JSONB for metadata
)
# Add embeddings to the vector store
vectorestore.add_embeddings(
texts=["your text data"], # Replace with your text data
embeddings=[[0.1, 0.2, 0.3]], # Replace with your embedding vectors
metadatas=[{"key": "value"}], # Replace with your metadata
ids=["your_id"] # Replace with your custom IDs
) Make sure to replace placeholders like To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
All reactions