Guides
Log In
Guides

LangChain Extensions

class langchain_ext.embedding.NuPICEmbedding(url='localhost:8000', protocol='http', model='nupic-sbert.base-v3', max_batch_size=64, concurrency=4, tokenizer_config=None)

Bases: Embeddings

NuPICEmbedding is an Langchain Embeddings class.
Uses NuPIC Inference Server to embed documents and sentences.

  • Parameters:
    Embeddings (class) – The LangChain Embeddings class.

__init__(url='localhost:8000', protocol='http', model='nupic-sbert.base-v3', max_batch_size=64, concurrency=4, tokenizer_config=None)

Initialize the NuPIC Client.

  • Parameters:
    • url (str , optional) – The URL of the NuPIC Inference Server, defaults to “localhost:8000”
    • protocol (str , optional) – The protocol to use, defaults to “http”. Can be “http”,
      “https” or “grpc”.
    • model (str , optional) – The model to use, defaults to “nupic-sbert.base-v3”
    • max_batch_size (int , optional) – The maximum batch size, defaults to 64
    • concurrency (int , optional) – Number of concurrent connections to the server,
      defaults to 4
    • tokenizer_config (Optional [**Mapping [**str , Any ] ] , optional) – Tokenizer configuration dictionary, defaults to
      None.
      path (str): Path for the pretrained transformers tokenizer. Raise
      TypeError or KeyError if not present.
      max_tokens_per_string (int, optional): Maximum number of tokens the
      tokenizer should return per string given to the tokenizer. Defaults
      to 64.

batchsize : int | None_ = 64

embed_documents(documents: List[str])

Embed a list of documents.

  • Parameters:
    documents (List [**str ]) – The list of documents to embed.
  • Returns:
    The list of embeddings.
  • Return type:
    List[List[float]]

embed_query(query: str)

Embed a query.

  • Parameters:
    query (str) – The query to embed.
  • Returns:
    Embedding of the query.
  • Return type:
    List[float]

model : str | None = 'nupic-sbert.base-v3'

protocol : str | None = 'http'

url : str | None = 'localhost:8000'

class langchain_ext.llm.NuPICLLM(url='localhost:8000', protocol='http', model='nupic-gpt.7b-corti.v0', inference_parameters=None)

Bases: LLM

NuPICLLM is an Langchain LLM class.
Uses NuPIC Inference Server to call an GPT model with a prompt.

  • Parameters:
    LLM (class) – The LangChain LLM class.

__init__(url='localhost:8000', protocol='http', model='nupic-gpt.7b-corti.v0', inference_parameters=None)

Initialize the NuPIC Client.

  • Parameters:
    • url (str , optional) – The URL of the NuPIC Inference Server, defaults to “localhost:8000”
    • protocol (str , optional) – The protocol to use, defaults to “http”. Can be “http”,
      “https” or “grpc”.
    • model (str , optional) – The model to use, defaults to “nupic-gpt.7b-corti.v0”
    • inference_parameters – Dictionary containing optional parameters

to be used,
: for inference by the model at the inference server.
min_new_tokens (int) = 0: Minimum number of tokens to generate by the
model
max_new_tokens (int) = 512: Maximum number of tokens to generate by
the model
do_sample (bool) = True: Whether or not to use sampling ; use greedy
decoding otherwise.
temperature (float) = 1.0: The value used to modulate the next token
probabilities.
top_k (int) = 50: The number of highest probability vocabulary tokens
to keep for top-k-filtering.
top_p (float) = 1.0: If set to float < 1, only the smallest set of
most probable tokens with probabilities that add up to top_p or higher
are kept for generation.
repetition_penalty (float) = 1.0: The parameter for repetition penalty.
1.0 meansno penalty.

client : Any | None

inferenceparameters : Mapping[str, Any] | None_

model : str | None

protocol : str | None

url : str | None

class langchain_ext.llm.NuPICLLMStreaming(url='localhost:8001', model='nupic-gpt.7b-corti.streaming.v0', inference_parameters=None, tokens_per_line=16)

Bases: LLM

NuPICLLM is an Langchain LLM class.
Uses NuPIC Inference Server to call an GPT model with a prompt.

  • Parameters:
    LLM (class) – The LangChain LLM class.

__init__(url='localhost:8001', model='nupic-gpt.7b-corti.streaming.v0', inference_parameters=None, tokens_per_line=16)

Initialize the NuPIC Client.

  • Parameters:
    • url (str , optional) – The URL of the NuPIC Inference Server, defaults to “localhost:8001”
    • model (str , optional) – The model to use, defaults to “nupic-gpt.7b-corti.streaming.v0”
    • inference_parameters (Optional [**Mapping [**str , Any ] ] , optional) – Dictionary containing optional parameters
      to be used, for inference by the model at the inference server.
      min_new_tokens (int) = 0: Minimum number of tokens to generate by the
      model
      max_new_tokens (int) = 512: Maximum number of tokens to generate by
      the model
      do_sample (bool) = True: Whether or not to use sampling ; use greedy
      decoding otherwise.
      temperature (float) = 1.0: The value used to modulate the next token
      probabilities.
      top_k (int) = 50: The number of highest probability vocabulary tokens
      to keep for top-k-filtering.
      top_p (float) = 1.0: If set to float < 1, only the smallest set of
      most probable tokens with probabilities that add up to top_p or higher
      are kept for generation.
      repetition_penalty (float) = 1.0: The parameter for repetition penalty.
      1.0 means no penalty.
    • tokens_per_line (int , optional) – Number of tokens per line, defaults to 16

client : Any | None

inferenceparameters : Mapping[str, Any] | None_

model : str | None

tokensin_cur_line : int_

tokensper_line : int_

url : str | None