delayedkarma/langchain-issues huggingface dataset:
LLama2c
Labels: name: auto:enhancement

Integrate https://github.com/karpathy/llama2.c to enable easy experimentation. 

Clone the repo:

```
git clone https://github.com/karpathy/llama2.c
```

To run with a prompt, get the inference file [that support prompt](https://github.com/karpathy/llama2.c/issues/62#issue-1819724122), which we name `run_with_prompt.c`:

```
wget https://raw.githubusercontent.com/myan-o/llama2.c/prompt/run.c
```

Compile it:

```
gcc -O3 -o run run_with_prompt.c -lm -funsafe-math-optimizations -Ofast -ffast-mat
```

Run in notebook:
```
from langchain_experimental.llms.llama2c import Llama2c
llm = Llama2c(
    directory="/Users/rlm/Desktop/Code/llama2.c/", model_dir="out44m/model44m.bin"
)
prompt = """Lily and Timmy are having a conversation.
Lily sed "Do you have any requests?".
Timmy replied to Lily, "can you give me something to eat".
Lily replied to Timmy"""
llm.stream(prompt=prompt)
```
corrections/improvements to my original submissions. documentation and wrapper
Labels: name: auto:improvement

<!-- Thank you for contributing to LangChain!

Replace this comment with:
The most important thing is the changes to the documentation/example notebook that i noticed and that a koboldai contributor has pointed out. 
  - Description:  I fixed a few typos and mistakes in the documentation example that could cause confusion.  The documentation is also now more interesting by showing it used in a chain. 
LLM wrapper: There is no changes to variable names or any other functionality that could potentially break things. I added a few extra optional parameters to the wrapper. I modified the wrapper call and stop sequences to function more like the textgen wrapper. I have thoroughly tested the stop_sequences in a chain and a regular call and confirmed they worked.
  - Issue: inaccurate and misleading info in my original documentation
  - Dependencies: n/a
  - Tag maintainer: for a quicker response, tag the relevant maintainer (see below),
  - Twitter handle: zanzibased

Please make sure you're PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

If you're adding a new integration, please include:
  1. a test for the integration, preferably unit tests that do not rely on network access,
  2. an example notebook showing its use.

Maintainer responsibilities:
  - General / Misc / if you don't know who to tag: @baskaryan
  - DataLoaders / VectorStores / Retrievers: @rlancemartin, @eyurtsev
  - Models / Prompts: @hwchase17, @baskaryan
  - Memory: @hwchase17
  - Agents / Tools / Toolkits: @hinthornw
  - Tracing / Callbacks: @agola11
  - Async: @agola11

If no one reviews your PR within a few days, feel free to @-mention the same people again.

See contribution guidelines for more information on how to write/run tests, lint, etc: https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md
 -->
Fixed grammar in LLM models documentation
Labels: name: lgtm, name: auto:documentation

Description: I fixed a typo in the documentation related to LLMs (https://python.langchain.com/docs/modules/model_io/models/llms/)
@baskaryan I hope I followed the correct procedure. This is literally my first contribution to open-source ever, so please let me know if I made any mistakes. I plan on studying the docs this week, and I will fix any other mistake I find.
removed namespace title
Labels: name: auto:documentation

Controversial!
This change compacts the left-side Navbar (ToC) of the [API Reference](https://api.python.langchain.com/en/latest/api_reference.html). 
Now almost each namespace item is split into two lines. For example `langchain.chat_models: Chat Models`
We remove the `Chat Models` and leave one the `langchain.chat_models`. 
This effectively compacts the navbar and increases the main page's usability. On my screen, it reduces # of lines in Toc from 28 t to 18, which is huge.

Removing the namespace "title" (like `Chat Models`) does not remove any information because the title is composed directly from the namespace.
API Reference users are developers. Usability for them is very important. We see less text => we find faster.

@baskaryan @hwchase17
Issue: Pinecone retriever with Cosine Similarity is treated like Cosine Distance
Labels: name: area: vector store, name: auto:bug, name: stale

### Issue you'd like to raise.

When using document search from the existing Pinecone index that was created using Cosine **Similarity** in the `ConversationalRetrievalChain`,  the `score_theshold` would eliminate most relevant documents instead of least relevant ones because the _similarity_ metric will be converted to _distance_.

In [_select_relevance_score_fn](https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/vectorstores/pinecone.py#L172) it calls the [_cosine_relevance_score_fn](https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/vectorstores/base.py#L169) - which converts the similarity returned from Pinecone search to distance.

Then, [filtering the documents](https://github.com/langchain-ai/langchain/blob/master/libs/langchain/langchain/vectorstores/base.py#L266) based on the `score_threshold` eliminates the most relevant documents instead of least relevant ones.

### Suggestion:

Pinecone subclass should override the `_cosine_relevance_score_fn` to preserve the similarity, since it is what originally comes back from the Pinecone similarity search.
Issue: how to get infomation when using Pinecone.from_texts
Labels: name: area: embeddings, name: area: vector store, name: auto:question

### Issue you'd like to raise.

```
dosearch = Pinecone.from_texts([t.page_content for t in split_docs], embeddings, index_name=index_name)
```
when I upsert the documents to Pinecone, If I want to get all the ids from `dosearch`, how I can do?

### Suggestion:

_No response_
Refactored `requests`
Labels: name: auto:refactor

Refactored `requests.py`. The same as https://github.com/langchain-ai/langchain/pull/7961 #8098 #8099 
requests.py is in the root code folder. This creates the `langchain.requests: Requests` group on the API Reference navigation ToC, on the same level as Chains and Agents which is incorrect.

Refactoring:

- copied requests.py content into utils/requests.py
- I added the backwards compatibility ref in the original requests.py. 
- updated imports to requests objects

@hwchase17, @baskaryan
Refactored `input`
Labels: name: auto:refactor

Refactored `input.py`. The same as https://github.com/langchain-ai/langchain/pull/7961 #8098 #8099 
input.py is in the root code folder. This creates the `langchain.input: Input` group on the API Reference navigation ToC, on the same level as Chains and Agents which is incorrect.

Refactoring:

- copied input.py file into utils/input.py
- I added the backwards compatibility ref in the original input.py. 
- changed several imports to a new ref

@hwchase17, @baskaryan
DOC: Apify integration missing
Labels: name: auto:documentation

### Issue with current documentation:

The Apify integration has been delete by @hwchase17 in commit aa0e69bc98fa9c77b01e5104f12b2b779f64fd33 and thus this documentation is not valid anymore:

https://python.langchain.com/docs/integrations/tools/apify

### Idea or request for content:

It would be highly beneficial to have information on a suitable replacement for the Apify integration.
Does not support llama-cpp verbose argument
Labels: name: auto:improvement

### Feature request

Add support llama-cpp verbose argument

### Motivation

missing

### Your contribution

Just add it in the init():

    ..........

    streaming: bool = True
    """Whether to stream the results, token by token."""

    verbose: bool = True

    @root_validator()
    def validate_environment(cls, values: Dict) -> Dict:
        """Validate that llama-cpp-python library is installed."""
        model_path = values["model_path"]
        model_param_names = [
            "lora_path",
            "lora_base",
            "n_ctx",
            "n_parts",
            "seed",
            "f16_kv",
            "logits_all",
            "vocab_only",
            "use_mlock",
            "n_threads",
            "n_batch",
            "use_mmap",
            "last_n_tokens_size",
            "verbose"
        ]
        model_params = {k: values[k] for k in model_param_names}
        .....
Azure Cognitive Search Indexing and Scoring
Labels: name: area: vector store, name: auto:enhancement

This is downstream of #6843 with fixes allowing merging after the [repo restructure](https://github.com/langchain-ai/langchain/discussions/8043) as well as linting and type fixes that now pass all tests.

This PR also safely removes the `azure-sdk-dev` custom install source.

  - Description: Adding support for custom index and scoring profile support in Azure Cognitive Search (#6843)
  - Dependencies: -
  - Tag maintainer: @rlancemartin, @eyurtsev, @hwchase17 

@ruoccofabrizio, @pablocastro, @farzad528, feel free review my changes as well. I made a new PR since it was easier. You can instead merge https://github.com/ruoccofabrizio/langchain/pull/1 if you want to preserve the original PR.

Closes #7841 Closes #8073 Closes #6843
Add Callbacks to Memory
Labels: name: area: memory, name: auto:improvement

Example using vector store memory: https://dev.smith.langchain.com/projects/p/2198839a-f5b8-4360-a010-e1e42a51660b/r/240428c7-dc80-45dd-b76d-b7869e0c18ff


Previously, all events happening within a memory class would be separate from the main run tree
Support chat in MLflow AI Gateway
Labels: name: enhancement, name: lgtm

Support chat in MLflow AI Gateway. cc @baskaryan 

**Testing**

Manual testing was conducted using the Databricks AI Gateway as follows:

```
from langchain.chat_models import ChatMLflowAIGateway
from langchain.schema import HumanMessage, SystemMessage

import mlflow.gateway
mlflow.gateway.set_gateway_uri("databricks")


chat = ChatMLflowAIGateway(temperature=0, route="corey-test", params={"temperature": 0.1})

messages = [
    SystemMessage(
        content="You are a helpful assistant that translates English to French."
    ),
    HumanMessage(
        content="Translate this sentence from English to French. I love programming a lot and things and stuff."
    ),
]
print(chat(messages))

batch_messages = [
    [
        SystemMessage(content="You are a helpful assistant that translates English to French."),
        HumanMessage(content="I love programming.")
    ],
    [
        SystemMessage(content="You are a helpful assistant that translates English to French."),
        HumanMessage(content="I love artificial intelligence.")
    ],
]
result = chat.generate(batch_messages)
print(result)

async def async_generate():
    resp = await chat.agenerate(batch_messages)
    print(resp)

import asyncio
asyncio.run(async_generate())
```

Output:

```
content="J'adore beaucoup la programmation et les choses et les trucs." additional_kwargs={} example=False
generations=[[ChatGeneration(text="J'adore la programmation.", generation_info={'finish_reason': 'stop'}, message=AIMessage(content="J'adore la programmation.", additional_kwargs={}, example=False))], [ChatGeneration(text="J'adore l'intelligence artificielle.", generation_info={'finish_reason': 'stop'}, message=AIMessage(content="J'adore l'intelligence artificielle.", additional_kwargs={}, example=False))]] llm_output={} run=[RunInfo(run_id=UUID('67e32bd6-c451-4196-ba77-e907c5cfcac7')), RunInfo(run_id=UUID('a08b7b88-e5e4-429c-85f6-b45bca942470'))]
generations=[[ChatGeneration(text="J'adore la programmation.", generation_info={'finish_reason': 'stop'}, message=AIMessage(content="J'adore la programmation.", additional_kwargs={}, example=False))], [ChatGeneration(text="J'adore l'intelligence artificielle.", generation_info={'finish_reason': 'stop'}, message=AIMessage(content="J'adore l'intelligence artificielle.", additional_kwargs={}, example=False))]] llm_output={} run=[RunInfo(run_id=UUID('9e3f3e0f-b051-40be-9ac7-7d903cc9ab78')), RunInfo(run_id=UUID('e7e63364-aa1b-47e4-9082-1763b17ad9cd'))]
```
Refactored `formatting`
Labels: name: lgtm

Refactored `formatting.py`. The same as https://github.com/langchain-ai/langchain/pull/7961 #8098 #8099 
formatting.py is in the root code folder. This creates the `langchain.formatting: Formatting` group on the API Reference navigation ToC, on the same level as Chains and Agents which is incorrect.

Refactoring:

- moved formatting.py content into utils/formatting.py
- I did not add the backwards compatibility ref in the original formatting.py. It seems unnecessary.

@hwchase17, @baskaryan
Bagatur/vercel test 3

<!-- Thank you for contributing to LangChain!

Replace this comment with:
  - Description: a description of the change, 
  - Issue: the issue # it fixes (if applicable),
  - Dependencies: any dependencies required for this change,
  - Tag maintainer: for a quicker response, tag the relevant maintainer (see below),
  - Twitter handle: we announce bigger features on Twitter. If your PR gets announced and you'd like a mention, we'll gladly shout you out!

Please make sure you're PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally.

If you're adding a new integration, please include:
  1. a test for the integration, preferably unit tests that do not rely on network access,
  2. an example notebook showing its use.

Maintainer responsibilities:
  - General / Misc / if you don't know who to tag: @baskaryan
  - DataLoaders / VectorStores / Retrievers: @rlancemartin, @eyurtsev
  - Models / Prompts: @hwchase17, @baskaryan
  - Memory: @hwchase17
  - Agents / Tools / Toolkits: @hinthornw
  - Tracing / Callbacks: @agola11
  - Async: @agola11

If no one reviews your PR within a few days, feel free to @-mention the same people again.

See contribution guidelines for more information on how to write/run tests, lint, etc: https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md
 -->
Extend Cube Semantic Loader functionality
Labels: name: lgtm

**PR Description:**

This pull request introduces several enhancements and new features to the `CubeSemanticLoader`. The changes include the following:

1. Added imports for the `json` and `time` modules.
2. Added new constructor parameters: `load_dimension_values`, `dimension_values_limit`, `dimension_values_max_retries`, and `dimension_values_retry_delay`.
3. Updated the class documentation with descriptions for the new constructor parameters.
4. Added a new private method `_get_dimension_values()` to retrieve dimension values from Cube's REST API.
5. Modified the `load()` method to load dimension values for string dimensions if `load_dimension_values` is set to `True`.
6. Updated the API endpoint in the `load()` method from the base URL to the metadata endpoint.
7. Refactored the code to retrieve metadata from the response JSON.
8. Added the `column_member_type` field to the metadata dictionary to indicate if a column is a measure or a dimension.
9. Added the `column_values` field to the metadata dictionary to store the dimension values retrieved from Cube's API.
10. Modified the `page_content` construction to include the column title and description instead of the table name, column name, data type, title, and description.

These changes improve the functionality and flexibility of the `CubeSemanticLoader` class by allowing the loading of dimension values and providing more detailed metadata for each document.
AttributeError: 'Redis' object has no attribute '_Redis__get_retriever_tags'. Did you mean: '_VectorStore__get_retriever_tags'?
Labels: name: area: vector store, name: auto:bug

### System Info

langchain ==  0.0.240
Python 3.10.9

### Who can help?

_No response_

### Information

- [ ] The official example notebooks/scripts
- [ ] My own modified scripts

### Related Components

- [ ] LLMs/Chat Models
- [ ] Embedding Models
- [ ] Prompts / Prompt Templates / Prompt Selectors
- [ ] Output Parsers
- [ ] Document Loaders
- [X] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

from langchain.chains import RetrievalQA
from langchain.indexes import VectorstoreIndexCreator
from langchain.text_splitter import CharacterTextSplitter
from langchain.embeddings import OpenAIEmbeddings

from langchain.llms import OpenAI
from langchain.document_loaders import PyPDFLoader
import os 
from langchain.vectorstores.redis import Redis




loader = PyPDFLoader("test.pdf")
documents = loader.load()
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
texts = text_splitter.split_documents(documents)
embeddings = OpenAIEmbeddings( deployment="text-embedding-ada-002",model="text-embedding-ada-002",chunk_size=1)
db = Redis.from_documents(
    texts, embeddings, redis_url="redis://localhost:6379", index_name="link"
)
retriever = db.as_retriever(search_type="similarity", search_kwargs={"k":2})
qa = RetrievalQA.from_chain_type(
    llm=OpenAI(), chain_type="stuff", retriever=retriever, return_source_documents=True)
query = "What is Compilance"
result = qa({"query": query})

print(result)



### Expected behavior

Getting the result of the query but having error at as_retriver() like  AttributeError: 'Redis' object has no attribute '_Redis__get_retriever_tags'. Did you mean: '_VectorStore__get_retriever_tags'?
Issue: Using HuggingFace Inference Endpoint as LLM in QA Chain
Labels: name: area: vector store, name: auto:improvement

### Issue you'd like to raise.

Hi there, I've been trying to come up with a system that can do the following:

1. take in a string as input (much longer len than the 512 token limit of the flan-t5-large model I'm using)
2. Use vector db (currently using FAISS) + langchain to index and query for relevant chunks
3. Use a model I've deployed at a HF endpoint to get inference for a question I have relating to the data

I've been able to achieve this just fine using the Huggingfacehub() class to create the LLM for the chain, but this uses the HF free inference endpoint, which of course has rate limits and is slow, which is why I'd like to use my own endpoint. I have not been able to find a way to use my endpoint in place of the free endpoint, and I've looked everywhere. I'm hoping it's something simple I've overlooked but any help would be greatly appreciated.

It would amazing I could see a specific Python example. Thanks in advance.

### Suggestion:

_No response_
DOC: Langchain integration with sagemaker missing
Labels: name: auto:documentation

### Issue with current documentation:

Hi,

The integration document for langchain with AWS sagemaker has been removed.
Do we have an updated doc for that.

[https://python.langchain.com/docs/modules/model_io/models/llms/integrations/sagemaker.html](url)

### Idea or request for content:

_No response_
Redis scores seems to be sorted from lowest to highest (with cosine)
Labels: name: area: vector store, name: auto:bug

### System Info

python = 3.10
langchain = 0.0.222

### Who can help?

_No response_

### Information

- [ ] The official example notebooks/scripts
- [ ] My own modified scripts

### Related Components

- [ ] LLMs/Chat Models
- [ ] Embedding Models
- [ ] Prompts / Prompt Templates / Prompt Selectors
- [ ] Output Parsers
- [ ] Document Loaders
- [X] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

Not sure how to give you all the steps but here attached a screenshot of the debugger run at line `vectorstores.redis` 338 and as you can see it goes from the lowest to the highest. You can see the `vector_score` on the right

<img width="1030" alt="Screenshot 2023-07-24 at 13 40 28" src="https://github.com/langchain-ai/langchain/assets/15908060/d9e5002e-8f31-4c68-acaf-f3e05ea1db63">


### Expected behavior

I think it should return from highest to lowest
Dynamic instruction for instructor embeddings
Labels: name: area: embeddings, name: auto:improvement

### Feature request

Provide a way to use instructor-based embeddings with dynamic instructions.

### Motivation

Currently HuggingFaceInstructEmbeddings initialized with instruction. This create problems with using multiple instructions, because this basically force you to initialize different instance for each instruction you need.  This is not a limitation of a model, you don't need to load it with different instructions every time.

### Your contribution

I can make a PR with another method, something like `embed_instruction_pairs`, which would take an list of [instruction, query] values, but want to discuss it first.
FEAT: Integrate Xinference LLMs and Embeddings
Labels: name: enhancement, name: lgtm

- [Xorbits Inference(Xinference)](https://github.com/xorbitsai/inference) is a powerful and versatile library designed to serve language, speech recognition, and multimodal models. Xinference supports a variety of GGML-compatible models including chatglm, whisper, and vicuna, and utilizes heterogeneous hardware and a distributed architecture for seamless cross-device and cross-server model deployment.
- This PR integrates Xinference models and Xinference embeddings into LangChain.
- Dependencies: To install the depenedencies for this integration, run
    
    `pip install "xinference[all]"`
    
- Example Usage:

To start a local instance of Xinference, run `xinference`.

To deploy Xinference in a distributed cluster, first start an Xinference supervisor using `xinference-supervisor`:

`xinference-supervisor -H "${supervisor_host}"`

Then, start the Xinference workers using `xinference-worker` on each server you want to run them on. 

`xinference-worker -e "http://${supervisor_host}:9997"`

To use Xinference with LangChain, you also need to launch a model. You can use command line interface (CLI) to do so. Fo example: `xinference launch -n vicuna-v1.3 -f ggmlv3 -q q4_0`. This launches a model named vicuna-v1.3 with `model_format="ggmlv3"` and `quantization="q4_0"`. A model UID is returned for you to use. 

Now you can use Xinference with LangChain:

```python
from langchain.llms import Xinference

llm = Xinference(
    server_url="http://0.0.0.0:9997", # suppose the supervisor_host is "0.0.0.0"
    model_uid = {model_uid} # model UID returned from launching a model
)

llm(
    prompt="Q: where can we visit in the capital of France? A:",
    generate_config={"max_tokens": 1024},
)
```

You can also use RESTful client to launch a model:
```python
from xinference.client import RESTfulClient

client = RESTfulClient("http://0.0.0.0:9997")

model_uid = client.launch_model(model_name="vicuna-v1.3", model_size_in_billions=7, quantization="q4_0")
```

The following code block demonstrates how to use Xinference embeddings with LangChain:
```python
from langchain.embeddings import XinferenceEmbeddings

xinference = XinferenceEmbeddings(
    server_url="http://0.0.0.0:9997",
    model_uid = model_uid
)
```

```python
query_result = xinference.embed_query("This is a test query")
```

```python
doc_result = xinference.embed_documents(["text A", "text B"])
```

Xinference is still under rapid development. Feel free to [join our Slack community](https://xorbitsio.slack.com/join/shared_invite/zt-1z3zsm9ep-87yI9YZ_B79HLB2ccTq4WA) to get the latest updates! 

- Request for review: @hwchase17, @baskaryan
- Twitter handle: https://twitter.com/Xorbitsio