Skip to main content

An integration package connecting ArangoDB and LangChain

Project description

🦜️🔗🥑 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_arangodb-2.1.0.tar.gz (39.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_arangodb-2.1.0-py3-none-any.whl (42.2 kB view details)

Uploaded Python 3

File details

Details for the file langchain_arangodb-2.1.0.tar.gz.

File metadata

  • Download URL: langchain_arangodb-2.1.0.tar.gz
  • Upload date:
  • Size: 39.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for langchain_arangodb-2.1.0.tar.gz
Algorithm Hash digest
SHA256 da4b089058dbb075cb19b3f0fdcd40898217d5dd2a9b489c8e8bc1e9f20dc90b
MD5 cd650a0dd0c1d1a6b85b812e2879d354
BLAKE2b-256 1ccfdf63b5f2c241629544c6970d8bc4fd687d9088e945826ba6bc3b3758f9ea

See more details on using hashes here.

File details

Details for the file langchain_arangodb-2.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_arangodb-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2916b9529f4db9f727b3cb00568ca2237a7c269b55b498421f92edae4a2089f1
MD5 a3968b361afeaec4162e455b94f61501
BLAKE2b-256 dcc39aa099465240b4526ac67ce2c70af5b3ee235ecc6e703d902f48f0a5cfa2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page