duohub retriever package for querying memories
Project description
duohub GraphRAG python client
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": "string",
"facts": [
{
"content": "string"
}
],
"token_count": 0
}
Token count is the number of tokens in the graph context. Regardless of your mode, you will get the same token content if you use the same query and memory ID on a graph.
Options
facts
: Whether to return facts in the response. Defaults toFalse
.assisted
: Whether to return an answer in the response. Defaults toFalse
.query
: The query to search the graph with.memoryID
: The memory ID to isolate your search results to.
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
) 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": "The capital of France is Paris.",
"facts": [],
"tokens": 100,
}
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 (located in facts
) will be a list of facts that are relevant to your query.
{
"payload": "subgraph_content",
"facts": [
{
"content": "Paris is the capital of France."
},
{
"content": "Paris is a city in France."
},
{
"content": "France is a country in Europe."
}
],
"token_count": 100
}
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": "Paris is the capital of France.",
"facts": [
{
"content": "Paris is the capital of France."
},
{
"content": "Paris is a city in France."
},
{
"content": "France is a country in Europe."
}
],
"token_count": 100
}
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file duohub-0.13.3.tar.gz
.
File metadata
- Download URL: duohub-0.13.3.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.13.0 Darwin/23.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6abf2f737b42b475aa892696797e14d017fd3d42fc27a39597d2157831325122 |
|
MD5 | df874e6ad362399e2948f37eb9c90aee |
|
BLAKE2b-256 | 318723fc9c089bfd0b810787725caeab5c4b7c15d7598feed575b050c539feb3 |
File details
Details for the file duohub-0.13.3-py3-none-any.whl
.
File metadata
- Download URL: duohub-0.13.3-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.13.0 Darwin/23.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bae913574f3aec26c6d4426df28b24d4b4d45f617a2042087415700fdb2bec47 |
|
MD5 | c87320472e20d4de55332d6f403a2632 |
|
BLAKE2b-256 | de1f73b0293b39c3d0b99c144f488d3dca3530131485cc3ba693198a98da12c0 |