Skip to main content

Vector Stores for Agents

Vector stores give your Agents the ability to store and retrieve knowledge from large document collections. This enables RAG (Retrieval Augmented Generation) where Agents can answer questions based on your custom data.

Agent with Vector Store Knowledge

import { Agent, createPineconeStore } from 'praisonai';

// Create vector store for Agent's knowledge
const vectorStore = createPineconeStore({
  apiKey: process.env.PINECONE_API_KEY!
});

// Create Agent with vector store knowledge
const agent = new Agent({
  name: 'Knowledge Assistant',
  instructions: 'You answer questions using the provided knowledge base.',
  knowledge: {
    vectorStore,
    indexName: 'company-docs'
  }
});

// Agent automatically retrieves relevant context
const response = await agent.chat('What is our refund policy?');

Supported Vector Stores

StoreDescriptionBest For
PineconeManaged vector databaseProduction Agents
WeaviateOpen-source with GraphQLHybrid search Agents
QdrantHigh-performanceSelf-hosted Agents
ChromaLightweight, embeddedDevelopment/Testing
MemoryIn-memoryUnit testing Agents

Agent with RAG Tool

Create a tool that lets your Agent search the vector store:
import { Agent, createTool, createPineconeStore } from 'praisonai';

const vectorStore = createPineconeStore({
  apiKey: process.env.PINECONE_API_KEY!
});

// Create search tool for the Agent
const searchKnowledge = createTool({
  name: 'search_knowledge',
  description: 'Search the knowledge base for relevant information',
  parameters: {
    type: 'object',
    properties: {
      query: { type: 'string', description: 'Search query' }
    },
    required: ['query']
  },
  execute: async ({ query }) => {
    const results = await vectorStore.query({
      indexName: 'documents',
      vector: await getEmbedding(query),
      topK: 5,
      includeMetadata: true
    });
    return results.map(r => r.content).join('\n\n');
  }
});

// Agent with knowledge search capability
const agent = new Agent({
  name: 'Research Assistant',
  instructions: 'Search the knowledge base to answer user questions accurately.',
  tools: [searchKnowledge]
});

const response = await agent.chat('Find information about our pricing plans');

Multi-Agent with Shared Knowledge

Multiple Agents can share the same vector store:
import { Agent, PraisonAIAgents, createPineconeStore } from 'praisonai';

const sharedKnowledge = createPineconeStore({
  apiKey: process.env.PINECONE_API_KEY!
});

// Research Agent - retrieves information
const researcher = new Agent({
  name: 'Researcher',
  instructions: 'Find relevant information from the knowledge base.',
  knowledge: { vectorStore: sharedKnowledge, indexName: 'docs' }
});

// Writer Agent - uses retrieved information
const writer = new Agent({
  name: 'Writer',
  instructions: 'Write clear responses based on the research provided.',
  knowledge: { vectorStore: sharedKnowledge, indexName: 'docs' }
});

const agents = new PraisonAIAgents({
  agents: [researcher, writer],
  tasks: [
    { agent: researcher, description: 'Research: {query}' },
    { agent: writer, description: 'Write a response based on the research' }
  ]
});

await agents.start({ query: 'What are our product features?' });

Agent that Builds Knowledge

An Agent can add documents to the vector store:
import { Agent, createTool, createPineconeStore } from 'praisonai';

const vectorStore = createPineconeStore({
  apiKey: process.env.PINECONE_API_KEY!
});

const addToKnowledge = createTool({
  name: 'add_to_knowledge',
  description: 'Add new information to the knowledge base',
  parameters: {
    type: 'object',
    properties: {
      content: { type: 'string', description: 'Content to store' },
      source: { type: 'string', description: 'Source of the information' }
    },
    required: ['content', 'source']
  },
  execute: async ({ content, source }) => {
    const embedding = await getEmbedding(content);
    await vectorStore.upsert({
      indexName: 'documents',
      vectors: [{
        id: `doc-${Date.now()}`,
        vector: embedding,
        content,
        metadata: { source, addedAt: new Date().toISOString() }
      }]
    });
    return `Added to knowledge base from ${source}`;
  }
});

const learningAgent = new Agent({
  name: 'Learning Agent',
  instructions: 'Learn new information and store it in the knowledge base.',
  tools: [addToKnowledge]
});

Vector Store Setup

Pinecone

import { createPineconeStore } from 'praisonai';

const pinecone = createPineconeStore({
  apiKey: process.env.PINECONE_API_KEY!
});

// Initialize index for Agent
await pinecone.createIndex({
  indexName: 'agent-knowledge',
  dimension: 1536,
  metric: 'cosine'
});

Weaviate

import { createWeaviateStore } from 'praisonai';

const weaviate = createWeaviateStore({
  host: 'your-cluster.weaviate.network',
  apiKey: process.env.WEAVIATE_API_KEY
});

Qdrant

import { createQdrantStore } from 'praisonai';

const qdrant = createQdrantStore({
  url: 'http://localhost:6333',
  apiKey: process.env.QDRANT_API_KEY
});

Memory (Testing)

import { createMemoryVectorStore } from 'praisonai';

// Perfect for testing Agents without external dependencies
const memory = createMemoryVectorStore();

Environment Variables

PINECONE_API_KEY=your-pinecone-key
WEAVIATE_API_KEY=your-weaviate-key
QDRANT_API_KEY=your-qdrant-key
OPENAI_API_KEY=your-openai-key  # For embeddings