Usage

The following examples demonstrate how to use AgensGraph with LangChain, both as a graph store for Cypher queries and as a vector store for semantic search. These code snippets provide a starting point for integrating AgensGraph into your LLM-powered applications.

AgensGraph Class

The AgensGraph class provides functionality to interact with agensgraph as a graphstore in langchain.

from langchain_agensgraph.graphs.agensgraph import AgensGraph

conf = {
    "dbname": "",
    "user": "",
    "password": "",
    "host": "",
    "port": ,
}

graph = AgensGraph(graph_name="", conf=conf)
graph.query("MATCH (n) RETURN n LIMIT 1;")

AgensgraphVector Class

The AgensgraphVector class provides functionality for managing an AgensGraph vector store. It enables you to create new vector indexes, add vectors to existing indexes, and perform queries using vector indexes.

from langchain.docstore.document import Document
from langchain_openai import OpenAIEmbeddings

from langchain_agensgraph.vectorstores.agensgraph_vector import AgensgraphVector

# Create a vector store from some documents and embeddings
docs = [
    Document(
        page_content=(
            "LangChain is a framework to build "
            "with LLMs by chaining interoperable components."
        ),
    )
]
embeddings = OpenAIEmbeddings(
    model="text-embedding-3-large",
    api_key="sk-...",  # Replace with your OpenAI API key
)
db = AgensgraphVector.from_documents(
    docs,
    embeddings,
    url="postgresql://username:password@host:port/dbname"
)
# Query the vector store for similar documents
docs_with_score = db.similarity_search_with_score("What is LangChain?", k=1)