Skip to main content

🦜️🔗🥑 LangChain ArangoDB

CI Docs

PyPI version badge Python versions badge

License Code style: black Downloads

This package contains the ArangoDB integration for LangChain.

📦 Installation

pip install -U langchain-arangodb

💻 Examples

ArangoGraph

The ArangoGraph class is a wrapper around ArangoDB's Python driver. It provides a simple interface for interacting with an ArangoDB database.

from arango import ArangoClient
from langchain_arangodb import ArangoGraph

db = ArangoClient(hosts="http://localhost:8529").db(username="root", password="password")

graph = ArangoGraph(db)

graph.query("RETURN 'hello world'")

ArangoChatMessageHistory

The ArangoChatMessageHistory class is used to store chat message history in an ArangoDB database. It stores messages as nodes and creates relationships between them, allowing for easy querying of the conversation history.

from arango import ArangoClient
from langchain_arangodb import ArangoChatMessageHistory

db = ArangoClient(hosts="http://localhost:8529").db(username="root", password="password")

history = ArangoChatMessageHistory(db=db, session_id="session_id_1")
history.add_user_message("hi!")
history.add_ai_message("whats up?")

print(history.messages)

ArangoVector

The ArangoVector class provides functionality for managing an ArangoDB Vector Store. It enables you to create new vector indexes, add vectors to existing indexes, and perform queries on indexes.

from arango import ArangoClient

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

# 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 = ArangoClient(hosts="http://localhost:8529").db(username="root", password="password")

vector_db = ArangoVector.from_documents(
    docs,
    embeddings,
    database=db,
)

# Query the vector store for similar documents
docs_with_score = vector_db.similarity_search_with_score("What is LangChain?", k=1)

ArangoGraphQAChain

The ArangoGraphQAChain class enables natural language interactions with an ArangoDB database. It uses an LLM and the database's schema to translate a user's question into an AQL query, which is executed against the database. The resulting data is then sent along with the user's question to the LLM to generate a natural language response.

from arango import ArangoClient

from langchain_openai import ChatOpenAI
from langchain_arangodb import ArangoGraph, ArangoGraphQAChain

llm = ChatOpenAI(
    temperature=0,
    api_key="sk-...",  # Replace with your OpenAI API key
)

db = ArangoClient(hosts="http://localhost:8529").db(username="root", password="password")

graph = ArangoGraph(db)

chain = ArangoGraphQAChain.from_llm(
    llm=llm, graph=graph, allow_dangerous_requests=True
)

chain.run("Who starred in Top Gun?")

🧪 Tests

Install the test dependencies to run the tests:

poetry install --with test,test_integration

Unit Tests

Run the unit tests using:

make tests

Integration Tests

  1. Start the ArangoDB instance using Docker:

    cd tests/integration_tests/docker-compose
    docker-compose -f arangodb.yml up
    
  2. Run the tests:

    make integration_tests
    

🧹 Code Formatting and Linting

Install the codespell, lint, and typing dependencies to lint and format your code:

poetry install --with codespell,lint,typing

To format your code, run:

make format

To lint it, run:

make lint

Metadata

Release files for langchain-arangodb 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-arangodb 2.1.0
File Size Uploaded
langchain_arangodb-2.1.0.tar.gz 39.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for langchain-arangodb 2.1.0
File Interpreter ABI Platform
langchain_arangodb-2.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 81.4 kB

Release files / langchain_arangodb-2.1.0.tar.gz

Download URL langchain_arangodb-2.1.0.tar.gz
Size 39.2 kB
Tags Source
SHA-256 checksum
How to use checksums
da4b089058dbb075cb19b3f0fdcd40898217d5dd2a9b489c8e8bc1e9f20dc90b
BLAKE2b-256 checksum
How to use checksums
1ccfdf63b5f2c241629544c6970d8bc4fd687d9088e945826ba6bc3b3758f9ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / langchain_arangodb-2.1.0-py3-none-any.whl

Download URL langchain_arangodb-2.1.0-py3-none-any.whl
Size 42.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2916b9529f4db9f727b3cb00568ca2237a7c269b55b498421f92edae4a2089f1
BLAKE2b-256 checksum
How to use checksums
dcc39aa099465240b4526ac67ce2c70af5b3ee235ecc6e703d902f48f0a5cfa2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

2.1.0 This release

2 release files

2.0.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.3

2 release files

1.0.2

2 release files

0.0.6

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page