Skip to main content

duohub retriever package for querying memories

Project description

duohub GraphRAG python client

PyPI version

This is a python client for the Duohub API.

Duohub is a blazing fast graph RAG service designed for voice AI and other low-latency applications. It is used to retrieve memory from your knowledege graph in under 50ms.

You will need an API key to use the client. You can get one by signing up on the Duohub app. For more information, visit our website: duohub.ai.

Table of Contents

Installation

pip install duohub

or

poetry add duohub

Usage

Basic usage is as follows:

from duohub import Duohub
client = Duohub(api_key="your_api_key")
response = client.query(query="What is the capital of France?", memoryID="your_memory_id")
print(response)

Output schema is as follows:

{
  "payload": [
    {
      "content": "string",
      "score": 1
    }
  ],
  "facts": [
    {
      "content": "string"
    }
  ],
  "sources": [
    {
      "id": "string",
      "name": "string", 
      "url": "string",
      "score": 1
    }
  ]
}

Options

  • facts: Whether to return facts in the response. Defaults to False.
  • assisted: Whether to return an answer in the response. Defaults to False.
  • query: The query to search the graph with.
  • memoryID: The memory ID to isolate your search results to.
  • top_k: Number of top memories to return. Defaults to 5.

Default Mode - Voice AI Compatible

When you only pass a query and memory ID, you are using default mode. This is the fastest option, and most single sentence queries will get a response in under 50ms.

from duohub import Duohub

client = Duohub(api_key="your_api_key")

response = client.query(query="What is the capital of France?", memoryID="your_memory_id")

print(response)

Default Mode Response

Your response (located in payload[0].content) is a string representation of a subgraph that is relevant to your query returned as the payload. You can pass this to your context window using a system message and user message template.

Assisted Queries - Voice AI Compatible

If you pass the assisted=True parameter to the client, the API will add reasoning to your query and uses the graph context to returns the answer. Assisted mode will add some latency to your query, though it should still be under 250ms.

Using assisted mode will improve the results of your chatbot as it will eliminate any irrelevant information before being passed to your context window, preventing your LLM from assigning attention to noise in your graph results.

from duohub import Duohub

client = Duohub(api_key="your_api_key")

response = client.query(query="What is the capital of France?", memoryID="your_memory_id", assisted=True)

print(response)

Assisted Mode Results

Assisted mode results will be a JSON object with the following structure:

{
    "payload": [
        {
            "content": "The capital of France is Paris.",
            "score": 1
        }
    ],
    "facts": [],
    "sources": []
}

Fact Queries

If you pass facts=True to the client, the API will return a list of facts that are relevant to your query. This is useful if you want to pass the results to another model for deeper reasoning.

Because the latency for a fact query is higher than default or assisted mode, we recommend not using these in voice AI or other low-latency applications.

It is more suitable for chatbot workflows or other applications that do not require real-time responses.

from duohub import Duohub

client = Duohub(api_key="your_api_key")

response = client.query(query="What is the capital of France?", memoryID="your_memory_id", facts=True)

print(response)

Fact Query Response

Your response will include both payload and facts:

{
  "payload": [
    {
      "content": "Paris is the capital of France.",
      "score": 1
    }
  ],
  "facts": [
    {
      "content": "Paris is the capital of France."
    },
    {
      "content": "Paris is a city in France."
    },
    {
      "content": "France is a country in Europe."
    }
  ],
  "sources": [
    {
      "id": "123",
      "name": "Wikipedia",
      "url": "https://wikipedia.org/wiki/Paris",
      "score": 1
    }
  ]
}

Combining Options

You can combine the options to get a more tailored response. For example, you can get facts and a payload:

from duohub import Duohub

client = Duohub(api_key="your_api_key")

response = client.query(query="What is the capital of France?", memoryID="your_memory_id", facts=True, assisted=True)

print(response)

Combining Options Response

Your response will be a JSON object with the following structure:

{
  "payload": [
    {
      "content": "Paris is the capital of France.",
      "score": 1
    }
  ],
  "facts": [
    {
      "content": "Paris is the capital of France."
    },
    {
      "content": "Paris is a city in France."
    },
    {
      "content": "France is a country in Europe."
    }
  ],
  "sources": [
    {
      "id": "123",
      "name": "Wikipedia",
      "url": "https://wikipedia.org/wiki/Paris",
      "score": 1
    }
  ]
}

Additional Methods

Adding Files

You can add files to Duohub using either local files or external URIs:

# Add a local file
response = client.add_file(file_path="path/to/your/file.txt")

# Add an external website or sitemap
response = client.add_file(
    external_uri="https://example.com",
    file_type="website"  # Options: 'website', 'sitemap', or 'website_bulk'
)

Creating a Memory

Create a new memory (graph or vector storage):

response = client.create_memory(
    name="My Memory",
    memory_type="graph",  # or "vector"
    description="Optional description",
    ontology="culture",  # Required for graph type. Options: culture, essays, support_requests
    chunk_size=250,  # Only for vector type
    chunk_overlap=10,  # Only for vector type (1-50)
    webhook_url="https://your-webhook.com",  # Optional
    acceleration=False  # Optional
)

Managing Files in Memory

Add files to an existing memory:

response = client.add_files_to_memory(
    memory_id="your_memory_id",
    files=["file_id_1", "file_id_2"]
)

Remove a file from memory:

response = client.delete_file_from_memory(
    memory_id="your_memory_id",
    file_id="file_id_to_remove"
)

Starting Ingestion

After adding files, start the ingestion process:

response = client.start_ingestion(
    memory_id="your_memory_id"
)

Note: The file management endpoints can only be used with memories created on or after 17-Dec-2024.

Contributing

We welcome contributions to this client! Please feel free to submit a PR. If you encounter any issues, please open an issue.

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

duohub-2.1.4.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

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

duohub-2.1.4-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file duohub-2.1.4.tar.gz.

File metadata

  • Download URL: duohub-2.1.4.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.12.7 Darwin/23.6.0

File hashes

Hashes for duohub-2.1.4.tar.gz
Algorithm Hash digest
SHA256 16e12db60f5338974c4e6e41006fcd40aeec57c37a64007bb6998e5390596989
MD5 64ebf2c02945bd90fd403b5bbbe5c546
BLAKE2b-256 e5e421a900cfca980f1bb9abb26743a42ff18dcffd1fc6f87b091d22b7aa5e86

See more details on using hashes here.

File details

Details for the file duohub-2.1.4-py3-none-any.whl.

File metadata

  • Download URL: duohub-2.1.4-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.12.7 Darwin/23.6.0

File hashes

Hashes for duohub-2.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8e31f8a3ed12540121b75400434a50ca5770446b60b5c18ab38a5250f65fd7fc
MD5 b665c92e38e7a1b9b985eba0fe8b1a2b
BLAKE2b-256 a1fd1f82773371fbe872a9d300bd04f5335e582075df3124d7401441c9d2d09f

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