class_docstr: Stores data in-memory. It's ephemeral and cannot be saved to disk.
docstr: Refer to the DocumentStore.write_documents() protocol documentation.
  
  If `policy` is set to `DuplicatePolicy.NONE` defaults to `DuplicatePolicy.FAIL`.
docstr_tok: ["Refer","to","the","DocumentStore.write_documents","(",")","protocol","documentation",".","If","`","policy","`","is","set","to","`","DuplicatePolicy.NONE","`","defaults","to","`","DuplicatePolicy.FAIL","`","."]
code: def write_documents(
      self,
      documents: List[Document],
      policy: DuplicatePolicy = DuplicatePolicy.NONE,
  ) -> int:
      """
      Refer to the DocumentStore.write_documents() protocol documentation.
  
      If `policy` is set to `DuplicatePolicy.NONE` defaults to `DuplicatePolicy.FAIL`.
      """
      if (
          not isinstance(documents, Iterable)
          or isinstance(documents, str)
          or any(not isinstance(doc, Document) for doc in documents)
      ):
          raise ValueError("Please provide a list of Documents.")
  
      if policy == DuplicatePolicy.NONE:
          policy = DuplicatePolicy.FAIL
  
      written_documents = len(documents)
      for document in documents:
          if (
              policy != DuplicatePolicy.OVERWRITE
              and document.id in self.storage.keys()
          ):
              if policy == DuplicatePolicy.FAIL:
                  raise DuplicateDocumentError(
                      f"ID '{document.id}' already exists."
                  )
              if policy == DuplicatePolicy.SKIP:
                  logger.warning("ID '%s' already exists", document.id)
                  written_documents -= 1
                  continue
          self.storage[document.id] = document
      return written_documents
  
imports: import re
  from typing import Literal, Any, Dict, List, Optional, Iterable
  import logging
  import numpy
  from haystack_bm25 import rank_bm25
  from tqdm.auto import tqdm
  from haystack import default_from_dict, default_to_dict
  from haystack.dataclasses import Document
  from haystack.document_stores.types import DuplicatePolicy
  from haystack.utils.filters import document_matches_filter, convert
  from haystack.document_stores.errors import DuplicateDocumentError, DocumentStoreError
  from haystack.utils import expit
label_desc: Use image node_id 6 for calling the InMemoryDocumentStore obj's underlying member method code with example usage: obj.write_documents(documents, policy) and returns: written_documents