Query
Retrieve information relevant to a specific query.
Before querying data, make sure to configure the API key in your environment.
In the current version, memories are eventually consistent. Memories may not be available for querying for up to 5 minutes after adding them for the first time.
You can query a graph by using the query
method.
The graph_id
is an optional parameter. If not set, it defaults to the default
graph.
The res.response
will be a natural language response to your query.
Include references
Using the keyword with_references
, it is possible to include the references to the sources used to generate an answer.
These sources can then be formatted and injected into the answer with the function .format_references
.
It is possible to provide custom formatting when injecting the references by passing a custom replacing function to .format_references
(the default being lambda i, _: f"[{i}]"
).
For example, assuming each memory’s metadata contains a URL, we can provide markdown formatting with links to the sources used.
where i
is an incremental index automatically generated for each source used.
Only context
It is also possible to request only the context retrieved by Circlemind, skipping the answer generation step.
This can be helpful if, for example, you want to control the style used to generate your answer or to use custom LLMs.
To achieve this, it is simply necessary to specify the flag only_context=True
when querying a graph.
The context will be available via .context
:
Context length
By default, Circlemind reserves the following amount of tokens for each data source:
Data | # Tokens |
---|---|
Entities | 4000 |
Relations | 3000 |
Chunks | 9000 |
This behaviour can be customised by specifiying new values for each data source using the parameters entities_max_tokens
, relations_max_tokens
, chunks_max_tokens
. For example:
will return exclusively the chunk data.
Notes:
- when requesting a non-negative number of tokens, Circlemind will try to fill in any available token space from other sources (e.g., when reserving 100 tokens for entities and relations and 1000 for chunks, if the chunks only use 900 tokens, the remaining 100 available tokens will be distributed to entities and relations).
- use the special value “-1” to disable this behaviour and effectively reserve 0 tokens for the target data sources.