Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

对嵌入适配器有一些疑问 #176

Open
TedaLIEz opened this issue Jan 19, 2025 · 0 comments
Open

对嵌入适配器有一些疑问 #176

TedaLIEz opened this issue Jan 19, 2025 · 0 comments

Comments

@TedaLIEz
Copy link

content/选修-Advanced Retrieval for AI with Chroma/6. 嵌入适配器 Embedding Adaptors.ipynb 看完有一个最大的疑问是如果我得到了一个嵌入适配器模型,怎么把它用于我的RAG应用呢?这一部分也没有在该章节涉及

我尝试了下面的代码,但是感觉结果比不使用嵌入适配器模型还要差,这是为什么?

query_embeddings = embedding_function(generated_queries)
# best_matrix 就是已经训练好后的嵌入适配器模型矩阵
adapted_query_embeddings = np.matmul(best_matrix, np.array(query_embeddings).T).T
results = chroma_collection.query(query_embeddings=adapted_query_embeddings, n_results=10)
from tool import get_completion_from_messages
retrieved_documents = results['documents']
information = "\n\n".join(["\n".join(doc) for doc in retrieved_documents])
def rag(query, information):
    
    
    # 中文prompt
    messages = [
        {
            "role": "system",
            "content": "你是一个有用的专家级财务研究助手。你的用户正在询问年度报告中包含的信息相关的问题。"
                       "你将看到用户的问题和年度报告中的相关信息。请仅使用这些信息回答用户的问题。"
        },
        {"role": "user", "content": f"问题:{query}。\n信息:{information}"}
    ]
    response = get_completion_from_messages(messages)
    return response

print(rag("报告中是否提到失业率的变化?", information))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant