Retrieval Modes

duohub offers three primary retrieval modes when querying your knowledge graph or vector store: Raw, Assisted, and Facts. These can be used to suit your use case.

Raw Mode (Default)

Raw mode returns unprocessed matches from your memory store without AI assistance.

from duohub import Duohub
client = Duohub()
response = client.retrieve(
memory_id="your-memory-id",
query="What is the capital of France?",
assisted=False
)

Output Example (Vector Store):

{
  "payload": [
    {
      "content": "Paris is the capital and largest city of France, serving as the country's major economic, cultural, and political center. With a population of over 2 million in the city proper...",
      "metadata": {
        "source": "https://example.com/geography/france",
        "sourceTitle": "France Geography Guide"
      }
    },
    {
      "content": "As the capital of France since 987 CE, Paris has been home to numerous French monarchs. The city's rich history includes the construction of iconic landmarks like the Eiffel Tower and the Louvre...",
      "metadata": {
        "source": "https://example.com/history/paris",
        "sourceTitle": "Paris Historical Overview"
      }
    },
    {
      "content": "The Paris metropolitan area is one of the largest in Europe, with over 12 million inhabitants. The city is a global hub for fashion, gastronomy, art, and tourism, attracting millions of visitors annually...",
      "metadata": {
        "source": "https://example.com/cities/paris-stats",
        "sourceTitle": "Paris Demographics & Tourism"
      }
    }
  ],
  "token_count": 156
}

If you are using graph memory, the output will be a human readable string representing a subgraph collection of nodes and edges along with their descriptions.

When to use:

  • When you need direct access to the raw memory chunks
  • For implementing custom post-processing logic
  • When transparency in the retrieval process is crucial

Assisted Mode

Assisted mode uses AI to process the retrieved information and provide a coherent response. This is our suggested mode for most use cases as it will keep your context window clean.

from duohub import Duohub
client = Duohub()
response = client.retrieve(
memory_id="your-memory-id",
query="What is the capital of France?",
assisted=True
)

Output Example:

{
  "payload": "The capital of France is Paris. It is both the capital city and largest metropolitan area in the country.",
  "token_count": 42
}

When to use:

  • When you need a natural language response
  • For chatbots and user-facing applications
  • When you want to synthesize information from multiple sources

Facts Mode

Facts mode provides three supporting facts along with the response. It can be combined with either Raw or Assisted mode.

# Combined with Assisted mode
response = client.retrieve(
    memory_id="your-memory-id",
    query="What is the capital of France?",
    assisted=True,
    facts=True
)

Output Example:

{
  "payload": "The capital of France is Paris.",
  "facts": [
    { "content": "Paris is the capital of France" },
    { "content": "Paris has been France's capital since 987 CE" },
    { "content": "Paris is located in northern France" }
  ],
  "token_count": 42
}

When to use:

  • When you need to provide evidence for the response
  • For applications requiring transparency in decision-making
  • When building educational tools or fact-checking systems

Mode Combinations

The retrieval modes can be combined to suit your needs:

  1. Raw + Facts: Returns unprocessed chunks with supporting facts
  2. Assisted + Facts: Returns an AI-processed response with supporting facts (most common)

Note: When both assisted=True and raw=True are specified, the assisted mode takes precedence.

Best Practices

  • Start with Raw mode during development to understand the underlying data
  • Use Assisted mode for production applications with direct user interaction
  • Add Facts mode when source verification or transparency is important
  • Consider response time requirements - Raw mode is typically faster than Assisted mode