Memory: Retrieve v1

The retrieve memory API endpoint allows you to retrieve similar chunks from an existing memory on Langbase based on a query. This endpoint requires an Org or User API key.


Generate an Org/User API key

You will need to generate an API key to authenticate your requests. For more information, visit the Org/User API key documentation.


POST/v1/memory/retrieve

Retrieve similar chunks from multiple memory

Retrieve similar chunks by specifying the query and memory names in the request body.

Headers

  • Name
    Content-Type
    Type
    string
    Required
    Required
    Description

    Request content type. Needs to be application/json.

  • Name
    Authorization
    Type
    string
    Required
    Required
    Description

    Replace <YOUR_API_KEY> with your user/org API key.

Body Parameters

  • Name
    query
    Type
    string
    Required
    Required
    Description

    The search query for retrieving similar chunks.

  • Name
    memory
    Type
    Array<Memory>
    Required
    Required
    Description

    An array of memory objects from which to retrieve similar chunks.

    Memory Object

    interface Memory {
      name: string;
    }
    
    • Name
      name
      Type
      string
      Required
      Required
      Description

      The name of the memory.

  • Name
    topK
    Type
    number
    Description

    The number of top similar chunks to return from memory. Default is 20, minimum is 1, and maximum is 100.

POST
/v1/memory/retrieve
import {Langbase} from 'langbase';

const langbase = new Langbase({
  apiKey: '<YOUR_API_KEY>', // Replace with your API key
});

const results = await langbase.memory.retrieve({
  query: "What are the key features?",
  memory: [{ name: "product-docs" }]
});

Response

  • Name
    MemoryRetrieveResponse[]
    Type
    array
    Description

    The array of retrieve response objects returned by the API endpoint.

    MemoryRetrieveResponse

    interface MemoryRetrieveResponse {
      text: string;
      similarity: number;
      meta: Record<string, string>;
    }
    
    • Name
      text
      Type
      string
      Description

      Retrieved text segment from memory.

    • Name
      similarity
      Type
      number
      Description

      Similarity score between the query and retrieved text (0-1 range).

    • Name
      meta
      Type
      Record<string, string>
      Description

      Additional metadata associated with the retrieved text.

API Response

[
  {
    "text": "Key features include real-time collaboration, version control, and automated testing.",
    "similarity": 0.92,
    "meta": {
      "documentName": "features.md",
      "section": "overview"
    }
  },
  {
    "text": "The platform supports multiple programming languages and frameworks.",
    "similarity": 0.85,
    "meta": {
      "documentName": "technical-specs.md",
      "section": "compatibility"
    }
  }
]