Your First Query
Let's make your first API call to CognitiveX. This simple example demonstrates the core workflow.
The Basic Workflow
1
Store Knowledge
Add information to the Memory Layer
2
Query with Context
Ask questions using stored knowledge
3
Get Reasoning
Receive answers with explainable thought processes
Complete Example
hello-world.tstypescript
import { CognitiveXClient } from '@cognitivex/sdk';
// Initialize the client
const client = new CognitiveXClient({
apiKey: process.env.COGNITIVEX_API_KEY
});
async function firstQuery() {
// Step 1: Store some knowledge
console.log('Step 1: Storing knowledge...');
const memory = await client.memory.store({
content: `CognitiveX is a cognitive infrastructure platform
that provides multi-LLM support, advanced RAG,
and 85% cost reduction through intelligent caching.`,
tags: ['about', 'features'],
});
console.log('✓ Stored with ID:', memory.id);
// Step 2: Query with reasoning
console.log('\nStep 2: Querying with reasoning...');
const result = await client.cognition.reason({
query: 'What are the main benefits of CognitiveX?',
context: [memory.id], // Use the stored knowledge
reflection: true, // Enable reasoning capture
});
console.log('\n✓ Answer:', result.answer);
console.log('\n✓ Reasoning:', result.reasoning);
console.log('\n✓ Confidence:', result.confidence);
}
// Run the example
firstQuery().catch(console.error);Expected Output
When you run this example, you'll see:
bash
Step 1: Storing knowledge...
✓ Stored with ID: mem_abc123xyz
Step 2: Querying with reasoning...
✓ Answer: CognitiveX offers three main benefits:
1. Multi-LLM Support - Work with multiple AI providers
2. Advanced RAG - Retrieve relevant context automatically
3. Cost Reduction - Save 85% through intelligent caching
✓ Reasoning: I analyzed the stored content about CognitiveX
features and identified the three core value propositions...
✓ Confidence: 0.95What's Happening?
Memory Storage
Your content is automatically converted to embeddings and stored in pgvector. Tags help organize and filter your knowledge base.
Context Retrieval
When you query, CognitiveX automatically retrieves relevant context from your Memory Layer to enhance the response quality.
Reasoning Capture
With reflection enabled, the AI's thought process is captured and returned, making the decision explainable and auditable.
Next Steps
Now that you've made your first query, explore:
- • Core Concepts - Understand the architecture
- • SDK Reference - Explore all available methods
- • Examples - See real-world use cases
- • Best Practices - Optimize your usage