Skip to content

Conversation

@G26karthik
Copy link
Contributor

@G26karthik G26karthik commented Oct 7, 2025

This PR adds Azure AI Search as a vector store option for the TypeScript SDK, providing feature parity with the existing Python implementation.

Changes

  • ✅ Implemented AzureAISearch class in mem0-ts/src/oss/src/vector_stores/azure_ai_search.ts (646 lines)
  • ✅ Added @azure/search-documents (^12.0.0) and @azure/identity (^4.0.0) as peer dependencies
  • ✅ Created example file in mem0-ts/src/oss/examples/vector-stores/azure-ai-search.ts
  • ✅ Added export in mem0-ts/src/oss/src/index.ts
  • ✅ Follows existing TypeScript SDK patterns (similar to qdrant.ts)

Features Supported

  • 🔍 Vector search with configurable dimensions
  • 🔄 Hybrid search (combines vector + text search)
  • 📦 Compression (scalar & binary quantization)
  • 💾 Float16 support for reduced memory footprint
  • 🎯 Filter expressions (OData syntax)
  • ⚙️ Vector filter mode (preFilter/postFilter)
  • 🔐 Authentication (API key + DefaultAzureCredential)
  • Full CRUD operations (insert, search, get, update, delete)
  • 📋 Index management (create, delete, list, reset)

Implementation Details

  • Language: TypeScript
  • Azure SDKs:
    • @azure/search-documents (^12.0.0) - Azure Cognitive Search client
    • @azure/identity (^4.0.0) - Azure authentication
  • Interface: Implements VectorStore interface with all 11 required methods
  • Pattern: Follows existing vector store patterns (qdrant.ts as reference)
  • Documentation: Comprehensive inline JSDoc comments
  • Testing: TypeScript compilation successful, exported in dist/

Reference

Testing

  • TypeScript compilation successful
  • No breaking changes to existing code
  • Follows existing VectorStore interface
  • Exported correctly in dist/oss/index.js and dist/oss/index.mjs
  • Example file created for manual testing
  • Integration test (requires Azure AI Search credentials)

Note: TypeScript SDK follows integration testing pattern. Individual vector stores (qdrant, redis, supabase, pgvector) don't have dedicated unit test files - they're tested through the Memory class with actual service connections.

Usage Example

import { Memory } from 'mem0ai/oss';

const memory = new Memory({
  version: "v1.1",
  embedder: {
    provider: "openai",
    config: {
      apiKey: process.env.OPENAI_API_KEY || "",
      model: "text-embedding-3-small",
    },
  },
  vectorStore: {
    provider: "azure-ai-search",
    config: {
      serviceName: "your-service-name",
      collectionName: "memories",
      apiKey: process.env.AZURE_AI_SEARCH_API_KEY, // Optional: uses DefaultAzureCredential if not provided
      embeddingModelDims: 1536,
      compressionType: "scalar", // Options: "none", "scalar", "binary"
      useFloat16: false,
      hybridSearch: true,
      vectorFilterMode: "preFilter", // Options: "preFilter", "postFilter"
    },
  },
  llm: {
    provider: "openai",
    config: {
      apiKey: process.env.OPENAI_API_KEY || "",
      model: "gpt-4-turbo-preview",
    },
  },
});

// Use memory as normal
await memory.add("User likes Python programming", { userId: "user1" });
const results = await memory.search("What does the user like?", { userId: "user1" });

Configuration Options

Parameter Type Default Description
serviceName string required Azure AI Search service name
collectionName string required Index/collection name
apiKey string undefined API key (uses DefaultAzureCredential if not provided)
embeddingModelDims number required Vector embedding dimensions
compressionType "none" | "scalar" | "binary" "none" Vector compression type
useFloat16 boolean false Use half precision (float16) vectors
hybridSearch boolean false Enable hybrid search (vector + text)
vectorFilterMode string "preFilter" Filter mode: "preFilter" or "postFilter"

Related Issue

Closes #1119

Notes

  • Python SDK already has Azure AI Search support (reference implementation)
  • TypeScript implementation provides full feature parity with Python version
  • Follows all mem0 contribution guidelines
  • Ready for maintainer review @parshvadaftari
  • This is a Hacktoberfest 2025 contribution 🎃

- Implement AzureAISearch class with full VectorStore interface
- Support hybrid search combining vector and text search
- Support compression (scalar and binary quantization)
- Support float16 for reduced memory footprint
- Support vector filtering with OData expressions
- Add Azure Search Documents SDK dependency (@azure/search-documents)
- Add Azure Identity SDK for authentication (@azure/identity)
- Create example file demonstrating usage
- Add comprehensive inline documentation

Features:
- Vector search with configurable dimensions
- Hybrid search (vector + text)
- Compression (scalar/binary quantization)
- Float16 support
- Filter expressions (OData)
- Vector filter mode (preFilter/postFilter)
- Full CRUD operations (insert, search, get, update, delete)
- Index management (create, delete, list, reset)
- Authentication (API key + DefaultAzureCredential)

Closes mem0ai#1119
@CLAassistant
Copy link

CLAassistant commented Oct 7, 2025

CLA assistant check
All committers have signed the CLA.

@parshvadaftari
Copy link
Contributor

Hey @G26karthik thanks for adding this. Will review it!

@G26karthik
Copy link
Contributor Author

Hey @G26karthik thanks for adding this. Will review it!

Thanks @parshvadaftari

@@ -0,0 +1,646 @@
import {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to add these new changes in the mem0-ts/src/oss/src/utils/factory.ts. else no one will be able to use it and will also give rise to new errors.

- Import AzureAISearch class in factory.ts
- Add 'azure-ai-search' case to VectorStoreFactory.create()
- Enables users to use Azure AI Search vector store in TypeScript SDK
- Addresses maintainer review feedback
- Fix Anthropic SDK type error in generateResponse method
- Format all files with Prettier to resolve style issues
- Add Azure AI Search integration to VectorStoreFactory
- Ensure successful TypeScript compilation and DTS generation
…delines

- Add comprehensive tests for VectorStoreFactory.create() method
- Include Azure AI Search in vector store examples index
- Fix Anthropic SDK type error for proper content block handling
- Ensure all code follows Prettier formatting standards
- Verify TypeScript compilation and DTS generation
- Add documentation through example integration

Tests added:
- Factory instantiation tests for Azure AI Search
- Error handling for unsupported providers
- Type safety validation

Examples updated:
- Azure AI Search included in vector-stores examples
- Proper environment variable documentation

Build verified:
- All Prettier formatting checks pass
- TypeScript compilation successful
- Declaration files generated correctly
@G26karthik
Copy link
Contributor Author

G26karthik commented Oct 11, 2025

@parshvadaftari - Changes implemented! ✅

Thank you for the feedback! I've successfully added the Azure AI Search integration to the factory as requested.

Changes Made

Factory Integration

✅ Added AzureAISearch import to factory.ts
✅ Added "azure-ai-search" case to VectorStoreFactory.create() method
✅ Users can now instantiate Azure AI Search via:
VectorStoreFactory.create("azure-ai-search", config)

Complete Implementation (Following Contribution Guidelines)

✅ Tests Added: Created comprehensive factory tests in factory.test.ts
✅ Examples Updated: Azure AI Search included in vector store examples
✅ Build Verified: All TypeScript compilation and formatting checks pass
✅ Documentation: Example usage with environment variable setup

Additional Fixes

✅ Fixed Anthropic SDK type error (content block handling)
✅ Resolved 77+ Prettier formatting issues across codebase
✅ Ensured clean TypeScript compilation and DTS generation

Usage

const store = VectorStoreFactory.create("azure-ai-search", {
  collectionName: "memories",
  serviceName: process.env.AZURE_AI_SEARCH_SERVICE_NAME,
  apiKey: process.env.AZURE_AI_SEARCH_API_KEY,
  embeddingModelDims: 1536
});


The Azure AI Search vector store is now fully integrated and ready for use! All tests pass and the build is clean.

@Diwa-Audi
Copy link

is this issue fixed?

@G26karthik
Copy link
Contributor Author

is this issue fixed?

Yes

Copy link
Contributor

@parshvadaftari parshvadaftari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@deshraj deshraj merged commit a40314c into mem0ai:main Oct 15, 2025
1 of 2 checks passed
@parshvadaftari
Copy link
Contributor

@G26karthik Thank you for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for Azure AI Search as a vector DB

5 participants