import CharacterTextSplitterfrom langchain.vectorstores import PGEmbeddingfrom langchain.document_loaders import TextLoaderfrom langchain.docstore.document import Documentos.environ["DATABASE_URL"] = getpass.getpass("Database Url:")    Database Url:¬∑¬∑¬∑¬∑¬∑¬∑¬∑¬∑loader = TextLoader("state_of_the_union.txt")documents = loader.load()text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)docs = text_splitter.split_documents(documents)embeddings = OpenAIEmbeddings()connection_string = os.environ.get("DATABASE_URL")collection_name = "state_of_the_union"db = PGEmbedding.from_documents(    embedding=embeddings,    documents=docs,    collection_name=collection_name,    connection_string=connection_string,)query = "What did the president say about Ketanji Brown Jackson"docs_with_score: List[Tuple[Document, float]] = db.similarity_search_with_score(query)for doc, score in docs_with_score:    print("-" * 80)    print("Score: ", score)    print(doc.page_content)    print("-" * 80)Working with vectorstore in Postgres‚ÄãUploading a vectorstore in PG‚Äãdb = PGEmbedding.from_documents(    embedding=embeddings,    documents=docs,    collection_name=collection_name,    connection_string=connection_string,    pre_delete_collection=False,)Create HNSW Index‚ÄãBy default, the extension performs a sequential scan search, with 100% recall. You might consider creating an HNSW index for approximate nearest neighbor (ANN) search to speed up similarity_search_with_score execution time. To create the HNSW index on your vector column, use a create_hnsw_index function:PGEmbedding.create_hnsw_index(    max_elements=10000, dims=1536, m=8, ef_construction=16, ef_search=16)The function above is equivalent to running the below SQL query:CREATE INDEX ON vectors USING hnsw(vec) WITH (maxelements=10000, dims=1536, m=3, efconstruction=16, efsearch=16);The HNSW index options used in the statement above include:maxelements: Defines the maximum number of elements indexed. This is a
Postgres Embedding is an open-source vector similarity search for Postgres that uses  Hierarchical Navigable Small Worlds (HNSW) for approximate nearest neighbor search.
Postgres Embedding is an open-source vector similarity search for Postgres that uses  Hierarchical Navigable Small Worlds (HNSW) for approximate nearest neighbor search. ->: import CharacterTextSplitterfrom langchain.vectorstores import PGEmbeddingfrom langchain.document_loaders import TextLoaderfrom langchain.docstore.document import Documentos.environ["DATABASE_URL"] = getpass.getpass("Database Url:")    Database Url:¬∑¬∑¬∑¬∑¬∑¬∑¬∑¬∑loader = TextLoader("state_of_the_union.txt")documents = loader.load()text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)docs = text_splitter.split_documents(documents)embeddings = OpenAIEmbeddings()connection_string = os.environ.get("DATABASE_URL")collection_name = "state_of_the_union"db = PGEmbedding.from_documents(    embedding=embeddings,    documents=docs,    collection_name=collection_name,    connection_string=connection_string,)query = "What did the president say about Ketanji Brown Jackson"docs_with_score: List[Tuple[Document, float]] = db.similarity_search_with_score(query)for doc, score in docs_with_score:    print("-" * 80)    print("Score: ", score)    print(doc.page_content)    print("-" * 80)Working with vectorstore in Postgres‚ÄãUploading a vectorstore in PG‚Äãdb = PGEmbedding.from_documents(    embedding=embeddings,    documents=docs,    collection_name=collection_name,    connection_string=connection_string,    pre_delete_collection=False,)Create HNSW Index‚ÄãBy default, the extension performs a sequential scan search, with 100% recall. You might consider creating an HNSW index for approximate nearest neighbor (ANN) search to speed up similarity_search_with_score execution time. To create the HNSW index on your vector column, use a create_hnsw_index function:PGEmbedding.create_hnsw_index(    max_elements=10000, dims=1536, m=8, ef_construction=16, ef_search=16)The function above is equivalent to running the below SQL query:CREATE INDEX ON vectors USING hnsw(vec) WITH (maxelements=10000, dims=1536, m=3, efconstruction=16, efsearch=16);The HNSW index options used in the statement above include:maxelements: Defines the maximum number of elements indexed. This is a