# SemanticRetriever

    class SemanticRetriever: NSObject

Performs on-device semantic search, vector storage, and query retrieval on text, image, and audio files.
- `
  ### [create(fromComponents:)](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/SemanticRetriever.md.txt#/c:objc(cs)MPPSemanticRetriever(cm)createFromComponents:error:)

  ` Creates a new instance of `MPPSemanticRetriever` from the given `MPPSemanticRetrieverComponents`.

  #### Declaration

  Swift

      class func create(fromComponents components: SemanticRetrieverComponents) throws -> Self

  #### Parameters

  |---|---|
  | `components` | The components to configure the semantic retriever. |

  #### Return Value

  A new instance of `MPPSemanticRetriever`. `nil` if there is an error.
- `
  ### [init(components:)](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/SemanticRetriever.md.txt#/c:objc(cs)MPPSemanticRetriever(im)initWithComponents:error:)

  ` Initializes a new instance of `MPPSemanticRetriever` from the given `MPPSemanticRetrieverComponents`.

  #### Declaration

  Swift

      init(components: SemanticRetrieverComponents) throws

  #### Parameters

  |---|---|
  | `components` | The components to configure the semantic retriever. |

  #### Return Value

  A new instance of `MPPSemanticRetriever`. `nil` if there is an error.
- `
  ### [delete(withIds:)](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/SemanticRetriever.md.txt#/c:objc(cs)MPPSemanticRetriever(im)deleteWithIds:error:)

  ` Deletes records from the vector store for the given list of IDs.

  #### Declaration

  Swift

      func delete(withIds ids: [String]) throws

- `
  ### [delete(withMetadataFilter:)](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/SemanticRetriever.md.txt#/c:objc(cs)MPPSemanticRetriever(im)deleteWithMetadataFilter:error:)

  ` Deletes records from the vector store matching the metadata filter.

  #### Declaration

  Swift

      func delete(withMetadataFilter metadataFilter: [String: String]) throws

- `
  ### [deleteAllRecords()](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/SemanticRetriever.md.txt#/c:objc(cs)MPPSemanticRetriever(im)deleteAllRecordsWithError:)

  ` Deletes all records from the vector store.

  #### Declaration

  Swift

      func deleteAllRecords() throws

- `
  ### [getAllRecordIds()](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/SemanticRetriever.md.txt#/c:objc(cs)MPPSemanticRetriever(im)getAllRecordIdsWithError:)

  ` Retrieves all unique top-level record identifiers in the vector store.

  #### Declaration

  Swift

      func getAllRecordIds() throws -> [String]

- `
  ### [insertAudio(withId:filePath:)](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/SemanticRetriever.md.txt#/c:objc(cs)MPPSemanticRetriever(im)insertAudioWithId:filePath:error:)

  ` Inserts an audio file into the vector store.

  #### Declaration

  Swift

      func insertAudio(withId recordId: String, filePath: String) throws

- `
  ### [insertAudio(withId:filePath:metadata:)](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/SemanticRetriever.md.txt#/c:objc(cs)MPPSemanticRetriever(im)insertAudioWithId:filePath:metadata:error:)

  ` Inserts an audio file with associated metadata into the vector store.

  #### Declaration

  Swift

      func insertAudio(withId recordId: String, filePath: String, metadata: [String: String]) throws

- `
  ### [insertContent(withId:parts:)](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/SemanticRetriever.md.txt#/c:objc(cs)MPPSemanticRetriever(im)insertContentWithId:parts:error:)

  ` Inserts multi-modal parts into the vector store.

  #### Declaration

  Swift

      func insertContent(withId recordId: String, parts: [TaskPart]) throws

- `
  ### [insertContent(withId:parts:metadata:)](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/SemanticRetriever.md.txt#/c:objc(cs)MPPSemanticRetriever(im)insertContentWithId:parts:metadata:error:)

  ` Inserts multi-modal parts with associated metadata into the vector store.

  #### Declaration

  Swift

      func insertContent(withId recordId: String, parts: [TaskPart], metadata: [String: String]) throws

- `
  ### [insertDocument(withId:text:)](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/SemanticRetriever.md.txt#/c:objc(cs)MPPSemanticRetriever(im)insertDocumentWithId:text:error:)

  ` Inserts a text document into the vector store.

  #### Declaration

  Swift

      func insertDocument(withId recordId: String, text: String) throws

- `
  ### [insertDocument(withId:text:metadata:)](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/SemanticRetriever.md.txt#/c:objc(cs)MPPSemanticRetriever(im)insertDocumentWithId:text:metadata:error:)

  ` Inserts a text document with associated metadata into the vector store.

  #### Declaration

  Swift

      func insertDocument(withId recordId: String, text: String, metadata: [String: String]) throws

- `
  ### [insertImage(withId:filePath:)](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/SemanticRetriever.md.txt#/c:objc(cs)MPPSemanticRetriever(im)insertImageWithId:filePath:error:)

  ` Inserts an image into the vector store.

  #### Declaration

  Swift

      func insertImage(withId recordId: String, filePath: String) throws

- `
  ### [insertImage(withId:filePath:metadata:)](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/SemanticRetriever.md.txt#/c:objc(cs)MPPSemanticRetriever(im)insertImageWithId:filePath:metadata:error:)

  ` Inserts an image with associated metadata into the vector store.

  #### Declaration

  Swift

      func insertImage(withId recordId: String, filePath: String, metadata: [String: String]) throws

- `
  ### [retrieve(withEmbedding:limit:)](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/SemanticRetriever.md.txt#/c:objc(cs)MPPSemanticRetriever(im)retrieveWithEmbedding:limit:error:)

  ` Retrieves up to `limit` nearest records matching the precomputed query embedding.

  #### Declaration

  Swift

      func retrieve(withEmbedding queryEmbedding: [NSNumber], limit: Int) throws -> [RetrievalResult]

- `
  ### [retrieve(withEmbedding:limit:metadataFilter:)](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/SemanticRetriever.md.txt#/c:objc(cs)MPPSemanticRetriever(im)retrieveWithEmbedding:limit:metadataFilter:error:)

  ` Retrieves up to `limit` nearest records matching the precomputed query embedding and metadata filter.

  #### Declaration

  Swift

      func retrieve(withEmbedding queryEmbedding: [NSNumber], limit: Int, metadataFilter: [String: String]?) throws -> [RetrievalResult]

- `
  ### [retrieve(withParts:limit:)](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/SemanticRetriever.md.txt#/c:objc(cs)MPPSemanticRetriever(im)retrieveWithParts:limit:error:)

  ` Retrieves up to `limit` nearest records matching the multi-modal query parts.

  #### Declaration

  Swift

      func retrieve(withParts queryParts: [TaskPart], limit: Int) throws -> [RetrievalResult]

- `
  ### [retrieve(withParts:limit:metadataFilter:)](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/SemanticRetriever.md.txt#/c:objc(cs)MPPSemanticRetriever(im)retrieveWithParts:limit:metadataFilter:error:)

  ` Retrieves up to `limit` nearest records matching the multi-modal query parts and metadata filter.

  #### Declaration

  Swift

      func retrieve(withParts queryParts: [TaskPart], limit: Int, metadataFilter: [String: String]?) throws -> [RetrievalResult]

- `
  ### [retrieve(withText:limit:)](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/SemanticRetriever.md.txt#/c:objc(cs)MPPSemanticRetriever(im)retrieveWithText:limit:error:)

  ` Retrieves up to `limit` nearest records matching the query string.

  #### Declaration

  Swift

      func retrieve(withText queryText: String, limit: Int) throws -> [RetrievalResult]

- `
  ### [retrieve(withText:limit:metadataFilter:)](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/SemanticRetriever.md.txt#/c:objc(cs)MPPSemanticRetriever(im)retrieveWithText:limit:metadataFilter:error:)

  ` Retrieves up to `limit` nearest records matching the query string and metadata filter.

  #### Declaration

  Swift

      func retrieve(withText queryText: String, limit: Int, metadataFilter: [String: String]?) throws -> [RetrievalResult]

- `
  ### [~~retrieve(withEmbedding:topK:)~~](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/SemanticRetriever.md.txt#/c:objc(cs)MPPSemanticRetriever(im)retrieveWithEmbedding:topK:error:)

  `

  > [!CAUTION]
  > **Deprecated.** Use `retrieve(withEmbedding:limit:)` instead.

  Retrieves up to `limit` nearest records matching the precomputed query embedding.

  #### Declaration

  Swift

      func retrieve(withEmbedding queryEmbedding: [NSNumber], topK: Int) throws -> [RetrievalResult]

- `
  ### [~~retrieve(withEmbedding:topK:metadataFilter:)~~](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/SemanticRetriever.md.txt#/c:objc(cs)MPPSemanticRetriever(im)retrieveWithEmbedding:topK:metadataFilter:error:)

  `

  > [!CAUTION]
  > **Deprecated.** Use `retrieve(withEmbedding:limit:metadataFilter:)` instead.

  Retrieves up to `limit` nearest records matching the precomputed query embedding and metadata filter.

  #### Declaration

  Swift

      func retrieve(withEmbedding queryEmbedding: [NSNumber], topK: Int, metadataFilter: [String: String]?) throws -> [RetrievalResult]

- `
  ### [~~retrieve(withParts:topK:)~~](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/SemanticRetriever.md.txt#/c:objc(cs)MPPSemanticRetriever(im)retrieveWithParts:topK:error:)

  `

  > [!CAUTION]
  > **Deprecated.** Use `retrieve(withParts:limit:)` instead.

  Retrieves up to `limit` nearest records matching the multi-modal query parts.

  #### Declaration

  Swift

      func retrieve(withParts queryParts: [TaskPart], topK: Int) throws -> [RetrievalResult]

- `
  ### [~~retrieve(withParts:topK:metadataFilter:)~~](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/SemanticRetriever.md.txt#/c:objc(cs)MPPSemanticRetriever(im)retrieveWithParts:topK:metadataFilter:error:)

  `

  > [!CAUTION]
  > **Deprecated.** Use `retrieve(withParts:limit:metadataFilter:)` instead.

  Retrieves up to `limit` nearest records matching the multi-modal query parts and metadata filter.

  #### Declaration

  Swift

      func retrieve(withParts queryParts: [TaskPart], topK: Int, metadataFilter: [String: String]?) throws -> [RetrievalResult]

- `
  ### [~~retrieve(withText:topK:)~~](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/SemanticRetriever.md.txt#/c:objc(cs)MPPSemanticRetriever(im)retrieveWithText:topK:error:)

  `

  > [!CAUTION]
  > **Deprecated.** Use `retrieve(withText:limit:)` instead.

  Retrieves up to `limit` nearest records matching the query string.

  #### Declaration

  Swift

      func retrieve(withText queryText: String, topK: Int) throws -> [RetrievalResult]

- `
  ### [~~retrieve(withText:topK:metadataFilter:)~~](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/SemanticRetriever.md.txt#/c:objc(cs)MPPSemanticRetriever(im)retrieveWithText:topK:metadataFilter:error:)

  `

  > [!CAUTION]
  > **Deprecated.** Use `retrieve(withText:limit:metadataFilter:)` instead.

  Retrieves up to `limit` nearest records matching the query string and metadata filter.

  #### Declaration

  Swift

      func retrieve(withText queryText: String, topK: Int, metadataFilter: [String: String]?) throws -> [RetrievalResult]